Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Response from system or Exec

by engtech (Initiate)
on Nov 03, 2003 at 06:52 UTC ( [id://304031]=perlquestion: print w/replies, xml ) Need Help??

engtech has asked for the wisdom of the Perl Monks concerning the following question:

Venerable Monks, I am trying to reset a serial port from a CGI page using: system("sstty +rs 1a12","/"); I don't know if this is correct as I am very new to perl. I think I read somewhere that I can get a response from that command as well like a boolean or error level... Could anyone point me in the right direction??? Regards, Don

Replies are listed 'Best First'.
Re: Response from system or Exec
by sauoq (Abbot) on Nov 03, 2003 at 07:24 UTC
    I think I read somewhere that I can get a response from that command as well like a boolean or error level...

    If the return value of system() is positive, it contains the return value of the command you called and some other information. This is also available via the special variable $?. This is how you can get at that information (straight out of the docs):

    $exit_value = $? >> 8; $signal_num = $? & 127; $dumped_core = $? & 128;

    If system() returns a -1, that means it couldn't start the program at all. In which case, it will give you the reason in the $! special variable.

    Could anyone point me in the right direction???

    Sure... perldoc -f system

    -sauoq
    "My two cents aren't worth a dime.";
    
•Re: Response from system or Exec
by merlyn (Sage) on Nov 03, 2003 at 11:55 UTC
    Aside from the other posts in this thread, I'd also like to point out that:
    system("sstty +rs 1a12","/");
    is very unlikely to work, unless you have a command called "sstty +rs 1a12", and you want to pass it the single argument of "/".

    When you invoke the multi-arg system or exec or pipe-open, you assume complete responsibility for argument parsing, since no shell will decide that for you. The first argument will be precisely the command name (as found in the $ENV{PATH}, of course), and the remaining args are passed one-by-one (although a NUL character cannot be passed because of the underlying interfaces).

    Perhaps what you wanted was:

    system("sstty","+rs","1a12","/")

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: Response from system or Exec
by arthas (Hermit) on Nov 03, 2003 at 08:51 UTC

    Just an addition, since you're mentioning exec() in the subject of your question.

    While system() returns a value, be aware that exec() never returns, but replaces your program with the one you are calling using exec().

    Michele.

      Actually, exec might return, if 1) perl doesn't need to call the shell to execute the command (that is, exec is either given more than one argument, or a string which has no characters (except whitespace) that are special to the shell), and hence will call execvp directly, and 2) the command can't be called (usually because the file doesn't exists, or due to permission problems).

      See perldoc -f exec.

      Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://304031]
Approved by sauoq
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (10)
As of 2024-04-23 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found