is it possible?

Discussion in 'Perl Misc' started by Jerry Preston, Oct 20, 2004.

  1. I have been running a script out side Perl and having the data go into a
    file:

    system "$program $ID > id_list.dat";

    Is it possible to redirect the output in ward?

    $ID < system "$program $ID";

    Thanks,

    Jerry
     
    Jerry Preston, Oct 20, 2004
    #1
    1. Advertising

  2. Jerry Preston wrote:
    > I have been running a script out side Perl and having the data go
    > into a file:
    >
    > system "$program $ID > id_list.dat";


    Ok, so far so good.

    > Is it possible to redirect the output in ward?
    >
    > $ID < system "$program $ID";


    I am not sure at all what you are trying to achive (your description is
    rather, hmmmm, unusual).

    Are you simply trying to capture the output from your external program and
    assign it to a variable? If yes, then you may want to have a look at the
    documentation for the function that you are using, in particular the fourth
    sentence in the third paragraph:
    "[...] This is
    *not* what you want to use to capture the output from a command,
    for that you should use [...]"
    Or just the FAQ:
    " Why can't I get the output of a command with system()?"
    Or plain old Google (yes, this question comes up a few times every month).

    If you are looking for something else, then please accept my appologies, my
    crystal ball must have malfunctioned.

    jue
     
    Jürgen Exner, Oct 20, 2004
    #2
    1. Advertising

  3. Jerry Preston wrote:
    > I have been running a script out side Perl and having the data go into a
    > file:
    >
    > system "$program $ID > id_list.dat";
    >
    > Is it possible to redirect the output in ward?
    >
    > $ID < system "$program $ID";
    >
    > Thanks,
    >
    > Jerry
    >
    >


    Backticks:

    $output = `$program $ID`;

    Note that this only gets you STDOUT - stderr will not be caught. Backticks also
    do not have the more secure forms like system's multiple-argument form.

    MB
     
    Matthew Braid, Oct 20, 2004
    #3
  4. You are correct, I am trying to capture the output from your external
    program and assign it to a variable.

    I just tried:

    @ID = ( "$program", "$ID" );
    system( @ID );

    and I get what was passed in "$program", "$ID".

    Have I missed something?

    Thanks,

    Jerry

    "Jürgen Exner" <> wrote in message
    news:m_jdd.5900$5l3.1782@trnddc02...
    > Jerry Preston wrote:
    > > I have been running a script out side Perl and having the data go
    > > into a file:
    > >
    > > system "$program $ID > id_list.dat";

    >
    > Ok, so far so good.
    >
    > > Is it possible to redirect the output in ward?
    > >
    > > $ID < system "$program $ID";

    >
    > I am not sure at all what you are trying to achive (your description is
    > rather, hmmmm, unusual).
    >
    > Are you simply trying to capture the output from your external program and
    > assign it to a variable? If yes, then you may want to have a look at the
    > documentation for the function that you are using, in particular the

    fourth
    > sentence in the third paragraph:
    > "[...] This is
    > *not* what you want to use to capture the output from a

    command,
    > for that you should use [...]"
    > Or just the FAQ:
    > " Why can't I get the output of a command with system()?"
    > Or plain old Google (yes, this question comes up a few times every month).
    >
    > If you are looking for something else, then please accept my appologies,

    my
    > crystal ball must have malfunctioned.
    >
    > jue
    >
    >
     
    Jerry Preston, Oct 20, 2004
    #4
  5. "Jerry Preston" <> wrote in
    news:cl4jlu$7p$:

    [ Please do not top-post. If you don't know what this means, it is time for
    you read the posting guidelines for this group. ]

    > "Jürgen Exner" <> wrote in message
    > news:m_jdd.5900$5l3.1782@trnddc02...
    >> Jerry Preston wrote:
    >> > I have been running a script out side Perl and having the data go
    >> > into a file:
    >> >
    >> > system "$program $ID > id_list.dat";

    >>
    >> Ok, so far so good.
    >>
    >> > Is it possible to redirect the output in ward?
    >> >
    >> > $ID < system "$program $ID";

    >>
    >> I am not sure at all what you are trying to achive (your description
    >> is rather, hmmmm, unusual).
    >>
    >> Are you simply trying to capture the output from your external
    >> program and assign it to a variable? If yes, then you may want to
    >> have a look at the documentation for the function that you are using,


    > You are correct, I am trying to capture the output from your external
    > program and assign it to a variable.


    ....

    > Have I missed something?


    Yes, reading the documentation, especially since Jürgen specifically
    referred you to the section relevant to your request.

    perldoc -f system

    Sinan









    >> in particular the

    > fourth
    >> sentence in the third paragraph:
    >> "[...] This is
    >> *not* what you want to use to capture the output from a

    > command,
    >> for that you should use [...]"
    >> Or just the FAQ:
    >> " Why can't I get the output of a command with system()?"
    >> Or plain old Google (yes, this question comes up a few times every
    >> month).
    >>
    >> If you are looking for something else, then please accept my
    >> appologies,

    > my
    >> crystal ball must have malfunctioned.
    >>
    >> jue
    >>
    >>

    >
    >
     
    A. Sinan Unur, Oct 20, 2004
    #5
  6. Jerry Preston wrote:
    > You are correct, I am trying to capture the output from your external
    > program and assign it to a variable.
    >
    > I just tried:
    >
    > @ID = ( "$program", "$ID" );
    > system( @ID );
    >
    > and I get what was passed in "$program", "$ID".
    >
    > Have I missed something?


    <snip>
    Yes.

    (from `perldoc -q 'command'`)
    =begin
    How can I capture STDERR from an external command?

    There are three basic ways of running external commands:

    system $cmd; # using system()
    $output = ‘$cmd‘; # using backticks (‘‘)
    open (PIPE, "cmd │"); # using open()
    =cut

    `system` will get you the return code of the command being run.

    (from `perldoc -f system`)
    =begin

    The return value is the exit status of the program as returned
    by the "wait" call. To get the actual exit value shift right
    by eight (see below). See also "exec". 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. Return value of -1 indicates a failure
    to start the program (inspect $! for the reason).

    =cut

    The other two methods will get you the actual output from the command.

    Execute the perldoc commands from above (or visit
    http://www.perldoc.com/) for further information. If you're still
    stuck, post again.

    HTH

    Jim
     
    James Willmore, Oct 20, 2004
    #6
  7. I read it! It still did not work!! I had to add ("./$program", "$ID" ).

    Thanks,

    Jerry

    "A. Sinan Unur" <> wrote in message
    news:Xns958871272E4asu1cornelledu@132.236.56.8...
    > "Jerry Preston" <> wrote in
    > news:cl4jlu$7p$:
    >
    > [ Please do not top-post. If you don't know what this means, it is time

    for
    > you read the posting guidelines for this group. ]
    >
    > > "Jürgen Exner" <> wrote in message
    > > news:m_jdd.5900$5l3.1782@trnddc02...
    > >> Jerry Preston wrote:
    > >> > I have been running a script out side Perl and having the data go
    > >> > into a file:
    > >> >
    > >> > system "$program $ID > id_list.dat";
    > >>
    > >> Ok, so far so good.
    > >>
    > >> > Is it possible to redirect the output in ward?
    > >> >
    > >> > $ID < system "$program $ID";
    > >>
    > >> I am not sure at all what you are trying to achive (your description
    > >> is rather, hmmmm, unusual).
    > >>
    > >> Are you simply trying to capture the output from your external
    > >> program and assign it to a variable? If yes, then you may want to
    > >> have a look at the documentation for the function that you are using,

    >
    > > You are correct, I am trying to capture the output from your external
    > > program and assign it to a variable.

    >
    > ...
    >
    > > Have I missed something?

    >
    > Yes, reading the documentation, especially since Jürgen specifically
    > referred you to the section relevant to your request.
    >
    > perldoc -f system
    >
    > Sinan
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > >> in particular the

    > > fourth
    > >> sentence in the third paragraph:
    > >> "[...] This is
    > >> *not* what you want to use to capture the output from a

    > > command,
    > >> for that you should use [...]"
    > >> Or just the FAQ:
    > >> " Why can't I get the output of a command with system()?"
    > >> Or plain old Google (yes, this question comes up a few times every
    > >> month).
    > >>
    > >> If you are looking for something else, then please accept my
    > >> appologies,

    > > my
    > >> crystal ball must have malfunctioned.
    > >>
    > >> jue
    > >>
    > >>

    > >
    > >

    >
     
    Jerry Preston, Oct 20, 2004
    #7
  8. Jerry Preston

    ChrisO Guest

    Matthew Braid wrote:
    > Jerry Preston wrote:
    >
    >> I have been running a script out side Perl and having the data go into a
    >> file:
    >>
    >> system "$program $ID > id_list.dat";
    >>
    >> Is it possible to redirect the output in ward?
    >>
    >> $ID < system "$program $ID";
    >>
    >> Thanks,
    >>
    >> Jerry
    >>
    >>

    >
    > Backticks:
    >
    > $output = `$program $ID`;
    >
    > Note that this only gets you STDOUT - stderr will not be caught.


    my $rv = `$program $ID 2>&1`;

    -ceo
     
    ChrisO, Oct 20, 2004
    #8
  9. Jerry Preston <> wrote:

    > Subject: is it possible?



    I am asking you again to please put the subject of your article
    in the Subject of your article. Play nice!


    > system "$program $ID > id_list.dat";
    >
    > Is it possible to redirect the output in ward?



    Yes, and the documentation for system() tells you how to do that.

    You should read the documentation for the functions that you use you know...


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 20, 2004
    #9
  10. [ Please do not top-post.
    Text rearranged into a sensible order.
    ]


    Jerry Preston <> wrote:
    > "Jürgen Exner" <> wrote in message
    > news:m_jdd.5900$5l3.1782@trnddc02...



    >> Are you simply trying to capture the output from your external program and
    >> assign it to a variable? If yes, then you may want to have a look at the
    >> documentation for the function that you are using, in particular the

    > fourth
    >> sentence in the third paragraph:
    >> "[...] This is
    >> *not* what you want to use to capture the output from a

    > command,
    >> for that you should use [...]"
    >> Or just the FAQ:
    >> " Why can't I get the output of a command with system()?"



    > You are correct, I am trying to capture the output from your external
    > program and assign it to a variable.
    >
    > I just tried:
    >
    > @ID = ( "$program", "$ID" );



    You have some useless uses of double quotes there.

    perldoc -q vars

    What's wrong with always quoting "$vars"?


    > Have I missed something?



    Yes, you missed reading the reply that you are following up to!

    The docs that Jürgen pointed you to tell you how to do it, and it
    isn't the way you've shown.

    Why don't you just do it the way the docs say to?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 20, 2004
    #10
  11. "Jerry Preston" <> wrote in
    news:cl4pep$3jn$:

    > I read it!


    You read what?

    > It still did not work!!


    What did not work?

    > I had to add ("./$program", "$ID" ).


    Huh?

    Please stop top-posting and go ahead andread the posting guidelines. That
    way, you might learn how to ask a question. You might also put some effort
    into understanding responses to your posts. Your original question has been
    answered by Jürgen Exner, James Willmore and Matthew Braid. Yet you keep on
    posting gibberish.

    Sinan.
     
    A. Sinan Unur, Oct 20, 2004
    #11
  12. James Willmore <> writes:
    > (from `perldoc -q 'command'`)
    > =begin
    > How can I capture STDERR from an external command?
    >
    > There are three basic ways of running external commands:
    >
    > system $cmd; # using system()
    > $output = ‘$cmd‘; # using backticks (‘‘)
    > open (PIPE, "cmd │"); # using open()


    I don't know about others, but I'm getting some strange binary
    sequences above, where according to "perldoc -q command", when I run
    it, there should be simple backquotes and vertical bars. Just thought
    I'd point it out.
     
    Arndt Jonasson, Oct 20, 2004
    #12
  13. Arndt Jonasson wrote:
    > James Willmore <> writes:
    >
    >>(from `perldoc -q 'command'`)
    >>=begin
    >> How can I capture STDERR from an external command?
    >>
    >> There are three basic ways of running external commands:
    >>
    >> system $cmd; # using system()
    >> $output = ‘$cmd‘; # using backticks (‘‘)
    >> open (PIPE, "cmd │"); # using open()

    >
    >
    > I don't know about others, but I'm getting some strange binary
    > sequences above, where according to "perldoc -q command", when I run
    > it, there should be simple backquotes and vertical bars. Just thought
    > I'd point it out.


    My newsreader and me are having a bit of a disagreement. I didn't
    realize that the last post was sent with garbage. Sorry.

    Jim
     
    James Willmore, Oct 20, 2004
    #13
  14. Arndt Jonasson wrote:

    > I don't know about others, but I'm getting some strange binary
    > sequences above, where according to "perldoc -q command", when I run
    > it, there should be simple backquotes and vertical bars. Just thought
    > I'd point it out.


    According to my news client, the post you're referring to is encoded as
    UTF-8, whereas yours is ISO-8859-1. Your news reader apparently doesn't
    like UTF-8.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Oct 20, 2004
    #14
  15. Jerry Preston

    Ron Parker Guest

    On Wed, 20 Oct 2004 12:36:31 -0400, Sherm Pendley wrote:
    > Arndt Jonasson wrote:
    >
    >> I don't know about others, but I'm getting some strange binary
    >> sequences above, where according to "perldoc -q command", when I run
    >> it, there should be simple backquotes and vertical bars. Just thought
    >> I'd point it out.

    >
    > According to my news client, the post you're referring to is encoded as
    > UTF-8, whereas yours is ISO-8859-1. Your news reader apparently doesn't
    > like UTF-8.


    Backtick is part of plain ASCII. Some brain-damaged so-called email clients
    instead use a character in the private-use range in Unicode. If those
    were really backticks, their ISO-8859-1 and UTF-8 representations would have
    been identical.

    http://www.fourmilab.ch/webtools/demoroniser/


    --
    #macro R(L P)sphere{L F}cylinder{L P F}#end#macro P(V)merge{R(z+a z)R(-z a-z)R(a
    -z-z-z a+z)torus{1F clipped_by{plane{a 0}}}translate V}#end#macro Z(a F T)merge{
    P(z+a)P(z-a)R(-z-z-x a)pigment{rgbf 1}hollow interior{media{emission 3-T}}}#end
    Z(-x-x.2x)camera{location z*-10rotate x*90normal{bumps.02scale.05}}
     
    Ron Parker, Oct 20, 2004
    #15
  16. Jerry Preston

    Ben Morrow Guest

    Quoth Matthew Braid <>:
    >
    > Backticks:
    >
    > $output = `$program $ID`;
    >
    > Note that this only gets you STDOUT - stderr will not be caught. Backticks also
    > do not have the more secure forms like system's multiple-argument form.


    ....but grep perlipc for 'safe backtick' for how emulate them safely.

    Ben

    --
    Razors pain you / Rivers are damp
    Acids stain you / And drugs cause cramp. [Dorothy Parker]
    Guns aren't lawful / Nooses give
    Gas smells awful / You might as well live.
     
    Ben Morrow, Oct 21, 2004
    #16
    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. Michael Giagnocavo [MVP]

    Re: Is it possible....

    Michael Giagnocavo [MVP], Jun 28, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,226
    Michael Giagnocavo [MVP]
    Jun 28, 2003
  2. Ekkehard Kraemer

    Development on 98 possible at all?

    Ekkehard Kraemer, Sep 13, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    438
    Dino Chiesa [Microsoft]
    Sep 22, 2003
  3. Markus
    Replies:
    1
    Views:
    514
    Markus
    Nov 22, 2005
  4. Replies:
    4
    Views:
    309
    Kenny McCormack
    Feb 21, 2006
  5. Replies:
    10
    Views:
    501
    Chris Gonnerman
    Dec 14, 2007
Loading...

Share This Page