How to fetch output of some other script in the current running perl script?

Discussion in 'Perl Misc' started by ritugoyal12@gmail.com, Oct 25, 2007.

  1. Guest

    Hi,
    I want to execute some script (May or May not be perl script) from a
    perl script and print the output of that executed script.
    My Operating system are Windows and Mac OS(Unix).
    I was trying the following code without success:


    Code
    $Response = system("start test.wbt");
    print $Response;

    By the above code I am able to execute test.wbt but program doesnt
    wait for test.wbt to get executed.

    Please help me what i m doing wrong also it would be nice if somebody
    could explain me why the above program fails and how can I print the
    output of the executed programin the current program.

    Thanks!!!!!
     
    , Oct 25, 2007
    #1
    1. Advertising

  2. Re: How to fetch output of some other script in the current runningperl script?

    wrote:
    > Hi,
    > I want to execute some script (May or May not be perl script) from a
    > perl script and print the output of that executed script.
    > My Operating system are Windows and Mac OS(Unix).
    > I was trying the following code without success:
    >
    >
    > Code
    > $Response = system("start test.wbt");
    > print $Response;
    >
    > By the above code I am able to execute test.wbt but program doesnt
    > wait for test.wbt to get executed.
    >
    > Please help me what i m doing wrong also it would be nice if somebody
    > could explain me why the above program fails and how can I print the
    > output of the executed programin the current program.


    If you ask perldoc what "system" does, it would tell you that "The
    return value is the exit status of the program as returned by the "wait"
    call."
    The same paragraph would then tell you that "This is not what you want
    to use to capture the output from a command, for that you should use
    merely backticks or "qx//", as described in "`STRING`" in perlop.".

    HTH,

    Josef
    --
    These are my personal views and not those of Fujitsu Siemens Computers!
    Josef Möllers (Pinguinpfleger bei FSC)
    If failure had no penalty success would not be a prize (T. Pratchett)
    Company Details: http://www.fujitsu-siemens.com/imprint.html
     
    Josef Moellers, Oct 25, 2007
    #2
    1. Advertising

  3. wrote:
    > I want to execute some script (May or May not be perl script) from a
    > perl script and print the output of that executed script.
    > $Response = system("start test.wbt");
    > print $Response;
    >
    > By the above code I am able to execute test.wbt but program doesnt
    > wait for test.wbt to get executed.


    That can't be. system() will first execute whatever external command you
    pass as a parameter. Depending on what arguments you pass to system() it may
    or may not use the shell. For details please see the documentation for
    system().
    And of course it will wait for the external command to terminate, too.
    However it has no control over other processes that are launched by the
    external command in turn.

    > Please help me what i m doing wrong also it would be nice if somebody
    > could explain me why the above program fails and how can I print the
    > output of the executed programin the current program.


    The documentation of system() explains the reason very explicitly, please
    see the third paragraph, first and third sentence.

    It is also explained in FAQ
    "Why can't I get the output of a command with system()?"

    jue
     
    Jürgen Exner, Oct 25, 2007
    #3
  4. wrote in news::

    > Code
    > $Response = system("start test.wbt");
    > print $Response;
    >
    > By the above code I am able to execute test.wbt but program doesnt
    > wait for test.wbt to get executed.
    >
    > Please help me what i m doing wrong also it would be nice if somebody
    > could explain me why the above program fails and how can I print the
    > output of the executed programin the current program.


    You are using the system function. The system function does not do what
    you want it to do. Wouldn't you first consult the documentation for the
    system function:

    perldoc -f system

    Or, alternatively, you can use the HTML documentation that comes with
    ActiveState Perl:

    file:///C:/Perl/html/lib/pods/perlfunc.html#alphabetical_listing_of_perl_functions

    file:///C:/Perl/html/index.html

    Sinan


    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)
    clpmisc guidelines: <URL:http://www.augustmail.com/~tadmc/clpmisc.shtml>
     
    A. Sinan Unur, Oct 25, 2007
    #4
  5. Re: How to fetch output of some other script in the current runningperl script?

    wrote:
    > Hi,
    > I want to execute some script (May or May not be perl script) from a
    > perl script and print the output of that executed script.
    > My Operating system are Windows and Mac OS(Unix).
    > I was trying the following code without success:
    >
    >
    > Code
    > $Response = system("start test.wbt");
    > print $Response;
    >
    > By the above code I am able to execute test.wbt but program doesnt
    > wait for test.wbt to get executed.


    Maybe "start" runs "test.wbt" in the background?


    --
    Mails please to josef dot moellers
    and I'm on gmx dot de.
     
    Josef Moellers, Oct 27, 2007
    #5
    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:
    0
    Views:
    500
  2. Lyle Johnson
    Replies:
    11
    Views:
    196
    Pit Capitain
    Feb 9, 2007
  3. borniac
    Replies:
    0
    Views:
    96
    borniac
    Apr 18, 2004
  4. Jack
    Replies:
    3
    Views:
    634
    Tad J McClellan
    Dec 22, 2008
  5. Replies:
    4
    Views:
    303
    ccc31807
    Jul 29, 2011
Loading...

Share This Page