Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

process redirection

by pavan_gpk (Initiate)
on Jul 25, 2005 at 13:08 UTC ( [id://477795]=perlquestion: print w/replies, xml ) Need Help??

pavan_gpk has asked for the wisdom of the Perl Monks concerning the following question:

HI, I just want to know how to redirect my 'system' function output to a specified path or directory.. i mean.. i have one executable file and generates a file with .cab or .exe. i used 'system' function to execute the file and generating the specified file in my current directory..but i want to generate those files in my specified path.. thanks & regards, pavan.

Replies are listed 'Best First'.
Re: process redirection
by pbeckingham (Parson) on Jul 25, 2005 at 13:16 UTC

    What happens if you change directories first?



    pbeckingham - typist, perishable vertebrate.
      ...putting that into code and showing how to redirect the other output as well:-
      system( "cd $mydir; $command > cmd.log 2>\&1" );

      One world, one people

      Hi if i change my directory first 'system' cant fetch the executable file in that directory and giving error.. let me explain more clearly what exactly i am looking for i need to run 'build.exe' that generates .cab's/.exe's files in current directory not to STDOUT.but i need to generate those files in the specfied path or directory that i specify.. thanks pavan..
Re: process redirection
by bofh_of_oz (Hermit) on Jul 25, 2005 at 13:17 UTC
    system function only returns the exit status of the command; if you want to capture the output, you should use backticks:

    $result = `command`;
    Then, you can write this output to wherever you want it with something like this:

    open OUTFILE, "> /path/to/outfile.txt"; print OUTFILE $result; close OUTFILE;
     

    Alternately, if you do not want to process the output in Perl, you can just do something like this:

    system("command > /path/to/result.txt");
    However, in this case you probably wouldn't need to use Perl for it at all...

    HTH

    --------------------------------
    An idea is not responsible for the people who believe in it...

      but it's his executable that is generating the cab/exe file, it's not being returned on STDOUT. If this was the problem, he'd be complaining that he wasn't generating cab's/exe's at all, not just that they were in the wrong place.

      He needs to change directory as per pbeckingham suggests and anonymized user 468275 demonstrates. (or pass an output file parameter to his exe, if it has one)

      ---
      my name's not Keith, and I'm not reasonable.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-16 04:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found