For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > September 2007 > Process ID









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Process ID
Somu

2007-09-23, 9:59 pm

Thanks for the help. I did it using

system "tasklist >> temp";

open FH , "temp" ;
statements..
unlink ("temp"); #EOF
John W. Krahn

2007-09-24, 7:01 pm

Ken Foskey wrote:
> On Mon, 2007-09-24 at 05:13 +0530, Somu wrote:
>
> Consider this code snippet then, does this in one step. I am writing
> the output to a log only you can put all the logic into the loop.
>
> open( $process, '|-', $command ) or croak "Unable to create process
> $command, $!";
> while( $line = <$process> ) {


You are opening $command for piped *input* but you are trying to read from it?
Perhaps you meant:

open( $process, '-|', $command ) or croak "Unable to create process $command,
$!";


> print $log $line;
> }
> close( $process );


You should also verify that the pipe closed successfully:

close( $process ) or warn $! ? "Error closing '$command' pipe: $!"
: "Exit status $? from '$command'";




John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
Matthew Whipple

2007-09-24, 7:01 pm

untie or unlink? You had used unlink previously which closed and
deleted a temporary file while close only closes the file which would be
the proper way to terminate a pipe such as used in the solution.

Somu wrote:
> Great! Thanks.. How about using untie instead of close? Can i know ,
> phat is the difference between the two?
>
>


Matthew Whipple

2007-09-25, 4:00 am

perldoc -funtie
or more thoroughly perldoc perltie

untie is the way to go if you're dealing with a tied variable...if
you're not then it won't do anything (or at least it shouldn't). The
perltie doc will also hint at the greater range of tie'ing available
above database hashes.

Somu wrote:
> I meant
>
> untie $process ;
>
> instead of the close function. In the docs, it says untie is better
> than close. Why is it so? I only use untie while closing perl database
> hashes..
>
>


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com