how to use system command to launch a shell script ?

Discussion in 'Perl Misc' started by gniagnia, Feb 21, 2007.

  1. gniagnia

    gniagnia Guest

    Hi all,

    I've searched the www for hours but I still don't understand why this
    isn't working.

    I am writting a perl script (on a linux server) that needs to run a
    shell script (on the same linux server).
    So I tried the following :

    1 - exec "/path/to/my/shell_script.sh";

    2 - open EXIT, "/us/path/to/my/shell_script.sh |";

    3 - system "/path/to/my/shell_script.sh";

    Neither of these 3 attempts actually worked.....the shell script isnt
    launched by the linux server....

    What am i missing?

    Thanks a lot in advance
     
    gniagnia, Feb 21, 2007
    #1
    1. Advertising

  2. gniagnia wrote:
    > I am writting a perl script (on a linux server) that needs to run a
    > shell script (on the same linux server).
    > So I tried the following :
    >
    > 1 - exec "/path/to/my/shell_script.sh";
    >
    > 2 - open EXIT, "/us/path/to/my/shell_script.sh |";
    >
    > 3 - system "/path/to/my/shell_script.sh";
    >
    > Neither of these 3 attempts actually worked.....the shell script isnt
    > launched by the linux server....
    >
    > What am i missing?


    You forgot to ask perl for help. Why are you ignoring the return value/error
    codes?
    See e.g. "perldoc -f system" for details about how to extract them

    jue
     
    Jürgen Exner, Feb 21, 2007
    #2
    1. Advertising

  3. gniagnia

    gf Guest

    On Feb 21, 2:13 am, "gniagnia" <> wrote:
    > Hi all,
    >
    > I've searched the www for hours but I still don't understand why this
    > isn't working.
    >
    > I am writting a perl script (on a linux server) that needs to run a
    > shell script (on the same linux server).
    > So I tried the following :
    >
    > 1 - exec "/path/to/my/shell_script.sh";
    >
    > 2 - open EXIT, "/us/path/to/my/shell_script.sh |";
    >
    > 3 - system "/path/to/my/shell_script.sh";
    >


    Besides testing your return values and error codes, you might want to
    do preflight tests to see if the script exists as you expect it, i.e.,
    is it an executable file?

    (-f "/path/to/my/shell_script.sh" && -x _) && exec "/path/to/my/
    shell_script.sh"; ... or system() or `` or qx()

    And don't forget the standard

    use warnings;
    use strict;

    at the top of your code.
     
    gf, Feb 21, 2007
    #3
  4. gniagnia

    Joe Smith Guest

    gniagnia wrote:

    > Neither of these 3 attempts actually worked.....the shell script isnt
    > launched by the linux server....


    Server? Is this a stealth CGI question? You should say so.

    'perldoc -q CGI' shows a pointer to: http://www.perl.org/CGI_MetaFAQ.html

    I wouldn't be surprised if it was the case where a process running as
    user 'nobody' does not have permission to access files owned by 'gniagnia'.
    -Joe
     
    Joe Smith, Feb 21, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    5,771
    Jonathan Bromley
    Feb 18, 2005
  2. Christian Heimes
    Replies:
    0
    Views:
    611
    Christian Heimes
    Feb 27, 2008
  3. Gerardo Herzig
    Replies:
    1
    Views:
    1,106
    Philipp Pagel
    Feb 27, 2008
  4. Samuel A. Falvo II
    Replies:
    0
    Views:
    498
    Samuel A. Falvo II
    Oct 8, 2008
  5. moongeegee

    execute a shell script in a shell script

    moongeegee, Dec 3, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    258
    Ben Morrow
    Dec 4, 2007
Loading...

Share This Page