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

Hi, I'm new to using perl and completly lost.. I'm trying to use the exec command in the following manner exec 'test.sh -param1 $p1 -param2 $p2' or die "Can not run test.sh"; but my variables are coming out as being blank when I echo the incoming parameters in my test.sh script ... Can anyone help??? Thanks David

Replies are listed 'Best First'.
Re: Using Exec command with parameters
by gargle (Chaplain) on Sep 12, 2005 at 09:32 UTC

    Hi,

    Could you post the code please? It would help us to understand the problem a little better.

    However, passing $p1, $p2 in a single quoted string will never work because the variables will never be expanded to their real values. Try to use double quotes and use a syntax like:

    exec '/bin/echo', 'Your arguments are: ', @ARGV;
    --
    if ( 1 ) { $postman->ring() for (1..2); }
Re: Using Exec command with parameters
by marto (Cardinal) on Sep 12, 2005 at 09:28 UTC
    Hi dgarry,

    perldoc is your friend:

    exec '/bin/echo', 'Your arguments are: ', @ARGV;

    Also I notice this is your first post.
    If you have not already done so I would suggest having a read at the Guide to the Monastery.

    Hope this helps

    Martin
Re: Using Exec command with parameters
by davidrw (Prior) on Sep 12, 2005 at 12:59 UTC
    are you sure that exec is what you want and not system? Note that exec will never return ....
Re: Using Exec command with parameters
by sgifford (Prior) on Sep 12, 2005 at 15:40 UTC
    Your code is using single quotes, which won't interpolate variables (so you should be seeing $p1 and $p2 as you parameters instead of blank). Either use double-quotes, or else use the multi-argument form of exec.