[Israel.pm] system() on windows question

Mikhael Goikhman migo at homemail.com
Mon Dec 20 03:31:19 PST 2004

On 19 Dec 2004 11:06:23 +0200, Yossi.Itzkovich at ecitele.com wrote:
> I usually use Perl on Unix, but I was asked the following one by a PC
> person:
> @args=("mkdir","guyDir2");
> system (@args) && print $!;
> The stderr  gives something like :
> A subdirectory or file guyDir2 already exists.
> but the print command  gives:
> No such file or directory

Perl internal system functions like mkdir(), rmdir(), unlink() set $!.
On the contrary, system() only sets $?, it does not change $!. 

system() forks the process and exec's the given command, so the original
process has no way to know the command error message. (You may play with
STDERR file descriptor to catch it, but this is another subject.)

> The error status is 256

If you mean $?, then read "perldoc -f system" that explains how to
interpret it.

> What is the real error message? Why do I get  another one ?

The $! in your code was probably set by some previous unsuccessful system
function, like: open FILE, "<unexisting file".

Additionally, it is not guaranteed that shell utils dump to stderr the
same error message that perl system functions set in $!. It is usually
the case, since both shell utils and perl use perror() from libc to get
the error message. But it depends on the actual implementation of unix
utils that may decide to show any other error wording.


perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'

More information about the Perl mailing list