Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

running a perl file from within a perl file

by perly_newbie (Novice)
on Dec 17, 2009 at 02:21 UTC ( #813119=perlquestion: print w/ replies, xml ) Need Help??
perly_newbie has asked for the wisdom of the Perl Monks concerning the following question:

hello, Id like to know how to run a perl file from within a perl file. From cmd line it is easy: I can go to a folder in C and run ABC.pl with options like "
ABC.pl com1@115200 65
" I am having problem passing these arguments (com1@115200 65) from within another perl file. I am trying to use: "
my @args=(0); my $ filename = "ABC.pl"; @args = ("$filename com1@115200 65"); system(@args) == 0 or die "system @args failed: $?"; "
" The file can be run without the arguments easily. Plz let me know what is going on.

Comment on running a perl file from within a perl file
Select or Download Code
Re: running a perl file from within a perl file
by brap (Pilgrim) on Dec 17, 2009 at 02:47 UTC
    # 813119.pl: my @args=(0); my $ filename = "ABC.pl"; @args = ("$filename com1@115200 65"); system(@args) == 0 or die "system @args failed: $?";

    # ABC.pl: print join( ' / ', @ARGV), "\n";
    Mostly works for me. ABC.pl gets called, and displays
    com1 / 65
    I'd recommend quoting the '@' character in your @args assignment, as in:
    @args = ("$filename com1\@115200 65");
    Which changes the output to
    com1@115200 / 65
    What output are you seeing? Which version of perl (perl -V)?
      Hey thanks, for the reply I got it to work.
Re: running a perl file from within a perl file
by ikegami (Pope) on Dec 17, 2009 at 02:50 UTC
    my @cmd = ($filename, 'com1@115200', '65'); system({ $cmd[0] } @cmd) == 0 or die("system @cmd failed: $?\n")
    or
    my @cmd = ($^X, $filename, 'com1@115200', '65'); system({ $cmd[0] } @cmd) == 0 or die("system @cmd failed: $?\n")
Re: running a perl file from within a perl file
by matze77 (Friar) on Dec 17, 2009 at 12:46 UTC

    Hello!
    Nitpick:
    Could you please reformat your post a little:
    some code tags "<c> your code here </c>" would be fine ...
    Writeup Formatting Tips
    Its written directly below the writing box
    Thanks & a happy time at he monastery
    MH

      thanks I have modified my post

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2014-11-26 22:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (174 votes), past polls