Mail Archives: djgpp/2004/09/18/06:14:30
> From: =?ISO-8859-1?Q?Rafael_Garc=EDa?= <rafael_no_spam_no_ AT geninfor DOT com>
> Date: Fri, 17 Sep 2004 14:33:19 +0200
>
> I'm trying to decompress an archive from a C program and I use
>
> system("unzip prueba.zip");
>
> I intend to have an "unzip.bat" that will do the work, containing the
> details about format.
>
> but when there is no "unzip.bat" nor "unzip.exe" I get an interactive
> shell launched. I need to get an error code from system() and not to
> stop execution of main program.
>
> I'm running WinXP
I don't have XP around where I'm typing this, but on Windows 98 a
simple test program below works as I expect. (One difference between
XP and 98 is that the default shell is cmd.exe on XP while it is
command.com on 98, but I think XP should invoke command.com for DJGPP
program, since it thinks they are DOS programs. So I think you should
get the same output on XP as well.)
So please post what you get on your system from the program I wrote.
If my program gives the same output on XP, you will need to tell more
about your program, since obviously `system' works as expected.
--------------- Test program tsys.c ----------------------------
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char *argv[])
{
int ret;
char *prog;
if (argc <= 1)
prog = "foobar foo bar";
else
prog = argv[1];
ret = system (prog);
printf ("system(\"%s\") returned %d\n", prog, ret);
return 0;
}
------------------------ Compilation -------------------------
gcc -Wall -g -o tsys.exe tsys.c
------------------------ Running -----------------------------
D:\usr\djgpp\tmp>tsys
Bad command or file name
system("foobar foo bar") returned 0
The "Bad command or file name" message comes from command.com, since
there's no program named `foobar' on my system. The return value of
zero is also expected, since command.com always returns zero, even if
the command it tried to invoke failed.
D:\usr\djgpp\tmp>tsys "foobar.exe foo bar"
system("foobar.exe foo bar") returned -1
Note that this time, there's no "Bad command or file name" message and
the return value is -1. That is because DJGPP's `system' does not
call the shell when the command has the ".exe" extension; instead, it
looks for the program along PATH and if not found, returns a failure
code right away.
Please see if you get the same results on your machine with this test
program.
- Raw text -