Use of @WINAPI

Jun 13, 2008
12
0
#1
I want my alias to return an error code. QUIT doesn't suit since it quits a batch file along with an alias. So I want to use WinAPI's SetLastError. But executing
Code:
echo %@winapi[Kernel32.dll,SetLastError,20] > nul
echo %? # %_?
returns "0 # 0". Neither exit code for last internal command nor exit code for last external command was changed. I don't understand why. Any ideas?
 
#2
On Fri, 13 Jun 2008 12:59:10 -0500, you wrote:


>I want my alias to return an error code. QUIT doesn't suit since it quits a batch file along with an alias. So I want to use WinAPI's SetLastError. But executing
>Code:
>---------
>echo %@winapi[Kernel32.dll,SetLastError,20] > nul
>echo %? # %_?
>---------
>returns "0 # 0". Neither exit code for last internal command nor exit code for last external command was changed. I don't understand why. Any ideas?
Functions (@WINAPI) don't set _? or ?. _? will be the return code of ECHO (the
last internal command). This may not be very satisfying but you could set ?
with a batfile:

v:\> type seterror.btm
quit %1

v:\> alias foo
echo foo & seterror.btm 22

v:\> foo
foo

v:\> echo %?
22
 
#4
On Fri, 13 Jun 2008 13:38:43 -0500, you wrote:


>---Quote (Originally by vefatica)---
>This may not be very satisfying but you could set ? with a batfile:
>---End Quote---
>Thank you. This thought came into my mind, too :).
I wrote a trivial plugin command to set _?.

INT WINAPI SETERR ( WCHAR * psz )
{
return _wtoi(psz);
}

It works. Perhaps Rex would overload the RETURN command so it would set _? when
used in an alias.

v:\> alias foo `echo foo & seterr 666`

v:\> foo & echo %_?
foo
666
 
Jun 13, 2008
12
0
#5
Perhaps Rex would overload the RETURN command so it would set _? when used in an alias
Why RETURN? It's better to add a new option to QUIT - to make it possible to quit just an alias but not parent batch file.
 

samintz

Scott Mintz
May 20, 2008
1,313
11
Solon, OH, USA
#6
The problem is that ALIAS's are not commands/functions unto themselves.
They are just simple text substitution macros. You can see the true
expression by pressing ctrl+f.

So, using Vince's example:
Code:
alias foo=`echo foo & seterr 22`
if you type foo, then press Ctrl+F, you'll see foo get replaced with: echo
foo & seterr 22

-Scott




Raistlin <>
06/13/2008 04:33 PM
Please respond to



To
[email protected]
cc

Subject
RE: [Support-t-193] Re: Use of @WINAPI






Quote:
Originally Posted by vefatica
Perhaps Rex would overload the RETURN command so it would set _? when used
in an alias
Why RETURN? It's better to add a new option to QUIT - to make it possible
to quit just an alias but not parent batch file.
 
Jun 13, 2008
12
0
#7
Then all we need is new command SETERROR. Calling external batch file or using external plugin ain't good ways to perform such simple and trivial operation as setting the errorlevel.
 
#8
On Fri, 13 Jun 2008 15:33:45 -0500, you wrote:


>---Quote (Originally by vefatica)---
>Perhaps Rex would overload the RETURN command so it would set _? when used in an alias
>---End Quote---
>Why RETURN? It's better to add a new option to QUIT - to make it possible to quit just an alias but not parent batch file.
QUIT, RETURN, ... even EXIT, it doesn't matter to me which does it ...
whatever's easier I suppose.