directing output of system()

Discussion in 'Perl Misc' started by Murugesh, Mar 23, 2005.

  1. Murugesh

    Murugesh Guest

    Hi all,
    when system() is invoked, is there any way to direct the output into
    a file.
    Thanks
     
    Murugesh, Mar 23, 2005
    #1
    1. Advertising

  2. Murugesh wrote:
    > when system() is invoked, is there any way to direct the output into
    > a file.


    May I suggest that you read the documentation for system() instead of
    asking hundreds of programmers to read it for you.

    perldoc -f system

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Mar 23, 2005
    #2
    1. Advertising

  3. Murugesh

    Murugesh Guest

    Gunnar Hjalmarsson wrote:
    > Murugesh wrote:
    >
    >> when system() is invoked, is there any way to direct the output into
    >> a file.

    >
    >
    > May I suggest that you read the documentation for system() instead of
    > asking hundreds of programmers to read it for you.
    >
    > perldoc -f system
    >

    In doc, it is said that we can get the exit status of the command.My
    question is different.
     
    Murugesh, Mar 23, 2005
    #3
  4. Murugesh wrote:
    > Gunnar Hjalmarsson wrote:
    >> Murugesh wrote:
    >>> when system() is invoked, is there any way to direct the output into
    >>> a file.

    >>
    >> May I suggest that you read the documentation for system() instead of
    >> asking hundreds of programmers to read it for you.
    >>
    >> perldoc -f system

    >
    > In doc, it is said that we can get the exit status of the command.


    It also suggests (a couple of sentences later) another method for
    running system commands if you are interested in capturing the command's
    output.

    > My question is different.


    Different compared to what?

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Mar 23, 2005
    #4
  5. Murugesh <> wrote:

    > when system() is invoked, is there any way to direct the output into
    > a file.



    Yes, just you would in the shell.


    system "ls -l >redirected.file";


    Haven't you already tried that?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 23, 2005
    #5
  6. Murugesh wrote :
    > Hi all,
    > when system() is invoked, is there any way to direct the output into
    > a file.


    Seems quite simple to me (I hope I got you right):

    system('command 2>> /path/errors >> /path/results');

    Best regards
    Martin

    --
    perl -e '$S=[[73,116,114,115,31,96],[108,109,114,102,99,112],
    [29,77,98,111,105,29],[100,93,95,103,97,110]];
    for(0..3){for$s(0..5){print(chr($S->[$_]->[$s]+$_+1))}}'
     
    Martin Kissner, Mar 23, 2005
    #6
  7. Murugesh wrote:

    > Hi all,
    > when system() is invoked, is there any way to direct the output into
    > a file.


    Yes - don't use system(). ;-)

    Use backticks, qx(), or open() a pipe to receive the output.

    That's if you want to capture the output of the command for use in your Perl
    code - if *all* you need to do is direct it to a file, nothing else, then
    Tad's suggestion of a simple shell redirect is perfect.

    sherm--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Mar 23, 2005
    #7
  8. Murugesh

    Murugesh Guest

    Tad McClellan wrote:
    > Murugesh <> wrote:
    >
    >
    >> when system() is invoked, is there any way to direct the output into
    >>a file.

    >
    >
    >
    > Yes, just you would in the shell.
    >
    >
    > system "ls -l >redirected.file";
    > Yes!! I never thought that way! Thanks.
    >
    > Haven't you already tried that?
    >
    >
     
    Murugesh, Mar 23, 2005
    #8
  9. Murugesh

    Guest

    Murugesh <> wrote:
    > when system() is invoked, is there any way to direct the output into
    > a file.


    There are several ways I can think of to do this. One is implied within
    the documentation for system() itself.

    perldoc -f system
    perldoc -f open

    Chris
     
    , Mar 23, 2005
    #9
  10. Murugesh wrote:
    > Gunnar Hjalmarsson wrote:
    >> Murugesh wrote:
    >>
    >>> when system() is invoked, is there any way to direct the output into
    >>> a file.

    >>
    >>
    >> May I suggest that you read the documentation for system() instead of
    >> asking hundreds of programmers to read it for you.
    >>
    >> perldoc -f system
    >>

    > In doc, it is said that we can get the exit status of the command.My
    > question is different.


    In which way does the third sentence in the third paragraph of said
    documentation _not_ answer your question?

    jue
     
    Jürgen Exner, Mar 24, 2005
    #10
    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. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    436
    Steve C. Orr [MVP, MCSD]
    Jun 3, 2004
  2. Stu
    Replies:
    4
    Views:
    8,031
  3. Roy Epperson

    're-directing" System.err

    Roy Epperson, Nov 8, 2003, in forum: Java
    Replies:
    4
    Views:
    383
    Andrew
    Nov 11, 2003
  4. =?Utf-8?B?Q2hyaXNB?=

    directing page output to a New window from server-side?

    =?Utf-8?B?Q2hyaXNB?=, Dec 9, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    344
    =?Utf-8?B?Q2hyaXNB?=
    Dec 9, 2006
  5. Tim Slattery
    Replies:
    0
    Views:
    350
    Tim Slattery
    Oct 16, 2007
Loading...

Share This Page