Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

call a program inside another program

by Anonymous Monk
on Sep 06, 2007 at 03:00 UTC ( #637311=perlquestion: print w/ replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,
I have a perl program and in that I am calling another perl program an +d passing some parameters. How can I do that? ======================= #!/usr/bin/perl print "hello"; "username" "userid" #How can i call using the above parameters? ======================== Thanks

Comment on call a program inside another program
Download Code
Replies are listed 'Best First'.
Re: call a program inside another program
by ikegami (Pope) on Sep 06, 2007 at 04:17 UTC

    There are different ways of calling other programs depending on whether the child should run in parallel or not, whether the child's output should be captured or not, etc.

    If you want to wait for the child program to finish executing before continuing, and you don't need to capture it's output or feed anything to it's STDIN, then you can use system.

    Windows: system(' "username" "userid"'); Elsewhere: system('', 'username', 'userid');

    Refer to system's documentation for more info including how to check if an error occured.

      You can also call system with a list on Win32:

      C:\>perl -e "system(qw/ 1 2 3/)" 1 2 3

        But system(LIST) is implemented as a barely disguised system(STRING). The below example tries to pass a string containing double quotes ('4 " and " 5') to a child Perl interpreter which prints out its @ARGV:

        Q:\>perl -e "$q=chr(34);system($^X, '-le', 'print for @ARGV', 1, 2, 3, +qq(4 $q and $q 5))" 1 2 3 4 and 5

        There would be ways to make system(LIST) saner but as the underlying OS call basically is system(STRING) and there is no central library routine for or consensus on deparsing the command line, and even the various MSVCRTs differ in how they deparse the command line, it's kinda hard.

        In Linux OS if I use code system('', 'username', 'userid'); How can I catch those values in
      Thanks a lot

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (2)
As of 2016-05-03 03:38 GMT
Find Nodes?
    Voting Booth?