> -----Original Message-----
> From: Andrew Tait [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, November 28, 2001 11:58 PM
> To: [EMAIL PROTECTED]
> Subject: Capturing Output from a program
> 
> 
> Hi All,
> 
> At the moment I am using the system() fuctions to run 
> external commands as
> follows:
> 
> print "Run \"userdel -r $arg\" [y/N] ";
> chop ($answer=<STDIN>);
> if ($answer =~ /^y/i) {
>         print "Deleting account....";
>         system("userdel -r $arg");
>         print "....Done\n";
> }
> 
> However, if  "system("userdel -r $arg");" prints any errors, 
> nothing appears
> on screen! For example, I am runng this script as a normal 
> user (not root),
> which should print the following error.
> 
> andrewt@sat:~$ userdel -r $arg
> bash: userdel: command not found

That error message is from your shell (bash), not from userdel.
userdel isn't being executed.

Since you don't use any shell metachars in your command, Perl
doesn't use the shell to execute it; it directly fork's and 
exec's your command. You have to test the return value from
system to see whether the command worked.

If userdel can be exec'd, you *will* see any messages it outputs.

You can force the shell to be used (and thus see the error
message above) by doing something like this:

   system("userdel -r $arg >&1");

But you really should just test the return value of system().

(Note that the "2>&1" construct by itself will not force the
shell to be used. Perl catches that construct and does the dup()
itself.)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to