Creating a piped stream and reading from it ???




This is a problem I often have. I would like to know if there
is a good alternative to using a temporary file.

Suppose I have:

$cmd = "ps -ef | grep $myuserid";

I could then do something like:


`$cmd > $tmpfile`;

open(TMP, $tmpfile);
while(<TMP>)
{
# various complex patterns processed etc.
...
...
}


It seems a little messy creating a temporary file and so on.
That's how I usually do it, but to do it right you have to
make it unique with pid as part of the name, make sure you delete it
when your done etc. On some machine the path to the temporary file may
change and so on.

What I really want to do is somehow run these piped commands from
inside
my script and then read the results in memory ideally or in a temporary
file. I read you can create a temporary file with a handle, but since
it has no name, I can't pipe to it.

The version of perl we have at work does not have File::Temporary, but
even if it did, I'm not sure I could get a filename recognizable by an
execed shell, I did read the method using IO::File, but it's the same
thing with that of course.

.



Relevant Pages

  • Re: problem deleting record in a text file
    ... > You will find below the script I wrote. ... > Actually the temporary file is created the way it should be but I didn't ... close TMPDAT or die $!; ... use warnings; # usually ...
    (perl.beginners)
  • Re: ASP Web Based nslookup
    ... temporary file, then on successful return of nslookup.exe read the file, ... An alternative method is to execute a piece of ... PerlScript ASP where if I remember rightly there is a much easier method ... I might be able to dig up some old script if ...
    (microsoft.public.inetserver.asp.db)
  • Re: ASP Web Based nslookup
    ... temporary file, then on successful return of nslookup.exe read the file, ... An alternative method is to execute a piece of ... PerlScript ASP where if I remember rightly there is a much easier method ... I might be able to dig up some old script if ...
    (microsoft.public.inetserver.asp.general)
  • Re: ASP Web Based nslookup
    ... temporary file, then on successful return of nslookup.exe read the file, ... An alternative method is to execute a piece of ... PerlScript ASP where if I remember rightly there is a much easier method ... I might be able to dig up some old script if ...
    (microsoft.public.inetserver.asp.components)
  • Re: avoid script running twice
    ... On 18/06/07, Robin Becker wrote: ... > Well I can think of a dumb way: create a temporary file during the ... > transaction and have your script check for that before running its main ... The exception that the second concurrent open/write ...
    (comp.lang.python)