| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| I found that when executing status=system('myprog') on Windows 2000, status is *always* zero afterwards, even if myprog sets an exit code. Can someone explain why this is so? Is there a way to run an external program and get its exit code on Windows? Ronald |
|
#2
| |||
| |||
| In article <b1185d63-0db5-43ec-8f39-51463a6f7c06@26g2000hsk.googlegroups.com>, Ronny <ro.naldfi.scher@gmail.com> wrote: >I found that when executing > > status=system('myprog') > >on Windows 2000, status is *always* zero afterwards, >even if myprog sets an exit code. > >Can someone explain why this is so? > >Is there a way to run an external program and get its exit >code on Windows? > >Ronald Do you have a C compiler? Do you know how to use it? |
|
#3
| |||
| |||
| On Fri, 11 Jul 2008 03:08:13 -0700, Ronny wrote: > I found that when executing > > status=system('myprog') > > on Windows 2000, status is *always* zero afterwards, even if myprog sets > an exit code. > > Can someone explain why this is so? > > Is there a way to run an external program and get its exit code on > Windows? Your syntax throws sytax errors under XP because of the single quotes instead of the required double quotes. Otherwise, with "", I can't get it not to work with my test .com program (it returns the ASCII code of a keypress). You may be using a Windows program or some other that doesn't return an exit code ... or the zero return may be correct. This debug script creates GETCH.COM, the above mentioned test program, a XOR AX,AX INT 16 MOV AH,4C INT 21 rcx 8 ngetch.com w q then awk "BEGIN{ print system(\"getch\")}" should display the ASCII code of the letter key you press. Note that the test .com is very nearly the smallest possible executable that is actually useful: eight bytes. -- T.E.D. (tdavis@mst.edu) |
|
#4
| |||
| |||
| Ronny escreveu: > I found that when executing > > status=system('myprog') > > on Windows 2000, status is *always* zero afterwards, > even if myprog sets an exit code. > > Can someone explain why this is so? > > Is there a way to run an external program and get its exit > code on Windows? > Which version of gawk? Do you have by any chance a variable COMSPEC set? If so, what does it contain? |
|
#5
| |||
| |||
| On Jul 11, 2:55 pm, Ted Davis <tda...@mst.edu> wrote: > On Fri, 11 Jul 2008 03:08:13 -0700, Ronny wrote: > > Is there a way to run an external program and get its exit code on > > Windows? > > Your syntax throws sytax errors under XP because of the single quotes > instead of the required double quotes. Actually, it would throw syntax error on *any* platform (even non- Win), but for a different reason. The quotes given don't have anything to do with Windows (the single quotes wouldn't be passed to the OS either), it is purely an awk issue: system() expects a string expression, in my case a string constant, and string constants in awk have to be delimited by double quotes. It was my fault not to post my example testprogram, which would be syntactically accepted. So here we go: END { status=system("DIR *.awk") print "status=",status status=system("seterlev 4") print "status=",status } seterlev is a program which is supposed to set the exit code (ERRORLEVEL) to 4 - more to this below. Executing this awk program with gawk -f stest.awk <NUL I get the output Datenträger in Laufwerk U: ist fischron Datenträgernummer: 0247-2660 Verzeichnis von U:\develsv\ARTS\playground 14.07.2008 15:18 128 stest.awk 1 Datei(en) 128 Bytes 0 Verzeichnis(se), 2.400.190.464 Bytes frei status= 0 status= 0 so both system() calls return status 0. Now you might suspect that seterlev does not set the exit code in the intended way (I downloaded it from the Net, and it could be buggy). But I can easily test it with the following Batch file: seterlev 4 if ERRORLEVEL 4 echo Error Level 4 or greater When I run this batch file, I get the output Error Level 4 or greater so we can trust that seterlev indeed returns the desired exit code. Ronald |
|
#6
| |||
| |||
| > Do you have a C compiler? Do you know how to use it? I have not installed a C compiler, but I don't see how this would help me with my present problem... Ronald |
|
#7
| |||
| |||
| On Jul 11, 8:43 pm, Cesar Rabak <csra...@yahoo.com.br> wrote: > > on Windows 2000, status is *always* zero afterwards, > > even if myprog sets an exit code. > > > Can someone explain why this is so? > > > Is there a way to run an external program and get its exit > > code on Windows? > > Which version of gawk? GNU Awk 3.1.0 (for native Windows, i.e. not Cygwin) > > Do you have by any chance a variable COMSPEC set? If so, what does it > contain? ComSpec=C:\WINNT\system32\cmd.exe so this looks good. |
|
#8
| |||
| |||
| In article <fa48ab24-8268-43e4-a55f-677a7ba49a27@27g2000hsf.googlegroups.com>, Ronny <ro.naldfi.scher@gmail.com> wrote: >> Do you have a C compiler? Do you know how to use it? > >I have not installed a C compiler, but I don't see how this would help >me with my present problem... > >Ronald > Then you need to think a little harder... |
|
#9
| |||
| |||
| Ronny said the following on 7/11/2008 5:08 AM: > I found that when executing > > status=system('myprog') > > on Windows 2000, status is *always* zero afterwards, > even if myprog sets an exit code. > > Can someone explain why this is so? > > Is there a way to run an external program and get its exit > code on Windows? > > Ronald I think you are kind of out of luck under windows since [g]awk does not try to determine what kind of executable is the object of the system call (exe, com, bat, cmd, etc...) so it just launches COMSPEC to determine this and execute the target. The target then returns an exit code to COMSPEC which then exits with it's own exit code of zero (indicating that it executed target successfully) unless later versions of COMSPEC have been modified to pass through the exit code. This is my educated guess as to how things have worked for me in the past. In cases where I needed to get information back from a system call, I resorted to have the system target write a file and read it into [g]awk to interpret the result. (Just my 2 cents which doesn't go far now-days :-) -- (^\pop/^) I'm lost... I've gone to look for myself. If I should return before I get back, keep me here. -- |
|
#10
| |||
| |||
| On Mon, 14 Jul 2008 06:26:40 -0700, Ronny wrote: > On Jul 11, 2:55 pm, Ted Davis <tda...@mst.edu> wrote: >> On Fri, 11 Jul 2008 03:08:13 -0700, Ronny wrote: >> > Is there a way to run an external program and get its exit code on >> > Windows? >> >> Your syntax throws sytax errors under XP because of the single quotes >> instead of the required double quotes. > > Actually, it would throw syntax error on *any* platform (even non- Win), > but for a different reason. The quotes given don't have anything to do > with Windows (the single quotes wouldn't be passed to the OS either), > it is purely an awk issue: system() expects a string expression, in my > case a string constant, and string constants in awk have to be delimited > by double quotes. It was my fault not to post my example testprogram, > which would be syntactically accepted. So here we go: > > END { > status=system("DIR *.awk") > print "status=",status > status=system("seterlev 4") > print "status=",status > } > } > seterlev is a program which is supposed to set the exit code (ERRORLEVEL) > to 4 - more to this below. Executing this awk program with > > gawk -f stest.awk <NUL > > I get the output > > Datenträger in Laufwerk U: ist fischron Datenträgernummer: 0247-2660 > > Verzeichnis von U:\develsv\ARTS\playground > > 14.07.2008 15:18 128 stest.awk > 1 Datei(en) 128 Bytes > 0 Verzeichnis(se), 2.400.190.464 Bytes frei > status= 0 > status= 0 > > so both system() calls return status 0. As expected for DIR - DIR is a CMD.EXE internal command and does not return an ERRORLEVEL. However, that is not the expected return from SETERLEV: (Screen dump) D:\MyFiles>awk "BEGIN{status = system(\"seterlev 4\"); print status}" 4 I cannot duplicate your problem under XP. -- T.E.D. (tdavis@mst.edu) |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.