| Author |
assigning variable to a pipe
|
|
|
| hi
i have a piece of code like this
open CMD ,"| wc -l " or die "blah blah: $!\n";
print CMD "ls -l" ;
how can i assign a variable (or array ) to store the output of print
CMD "ls -l" statement??
thanks...
| |
| Anno Siegel 2004-04-23, 5:46 am |
| mike <s99999999s2003@yahoo.com> wrote in comp.lang.perl.misc:
> hi
>
> i have a piece of code like this
>
> open CMD ,"| wc -l " or die "blah blah: $!\n";
> print CMD "ls -l" ;
>
> how can i assign a variable (or array ) to store the output of print
> CMD "ls -l" statement??
That's "assigning a variable to a pipe"?
It looks like what you're trying to do would be easier accomplished with
a shell script. With Perl, you want IPC::Open2 for that.
Anno
| |
|
| anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<c6ajsd$gs2$1@mamenchi.zrz.TU-Berlin.DE>...
> mike <s99999999s2003@yahoo.com> wrote in comp.lang.perl.misc:
>
> That's "assigning a variable to a pipe"?
>
> It looks like what you're trying to do would be easier accomplished with
> a shell script. With Perl, you want IPC::Open2 for that.
>
> Anno
hi,thanks for the advise
i went back to try this out :
use IPC::Open2;
$pid = open2(\*Reader, \*Writer, "sql -Uuser -Sserver -Ppassword" );
print Writer qq(select * from this_table\ngo);
$body .= $_ while (<Reader> );
print "$body\n";
But it doesn't work. Would appreciate if anyone can help
thanks
PS:
The original code was
open SQL, "| sql -Uuser -Sserver -Ppassword " or die "Failed to open pipe: $!" ;
print SQL "select \* from this_table";
and the intention was to assign the output to a variable
| |
| Tad McClellan 2004-04-24, 11:32 am |
| mike <s99999999s2003@yahoo.com> wrote:
> PS:
> The original code was
> open SQL, "| sql -Uuser -Sserver -Ppassword " or die "Failed to open pipe: $!" ;
> print SQL "select \* from this_table";
Why are you shelling out instead of using DBI.pm?
Your problem does not exist if you use DBI to communicate with your DB.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
| |
| James Willmore 2004-04-24, 12:32 pm |
| On Fri, 23 Apr 2004 22:55:25 -0700, mike wrote:
[ ... ]
> PS:
> The original code was
> open SQL, "| sql -Uuser -Sserver -Ppassword " or die "Failed to open pipe: $!" ;
> print SQL "select \* from this_table";
> and the intention was to assign the output to a variable
Is there some reason why you're not using the DBI module to interact with
your database (http://search.cpan.org/~timb/DBI-1.42/DBI.pm)? I see from
your code example that's what you *really* want to do.
Just my $0.02
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Arithmetic is being able to count up to twenty without taking
off your shoes. -- Mickey Mouse
| |
|
| James Willmore <jwillmore@remove.adelphia.net> wrote in message news:<pan.2004.04.24.15.07.05.347919@remove.adelphia.net>...
> On Fri, 23 Apr 2004 22:55:25 -0700, mike wrote:
> [ ... ]
>
>
> Is there some reason why you're not using the DBI module to interact with
> your database (http://search.cpan.org/~timb/DBI-1.42/DBI.pm)? I see from
> your code example that's what you *really* want to do.
>
> Just my $0.02
> HTH
>
> --
> Jim
>
> Copyright notice: all code written by the author in this post is
> released under the GPL. http://www.gnu.org/licenses/gpl.txt
> for more information.
>
> a fortune quote ...
> Arithmetic is being able to count up to twenty without taking
> off your shoes. -- Mickey Mouse
hi
i managed to solve the problem. Just need to close the handle "Writer" before
doing the reading. I did not use DBI.pm because i have trouble installing the
module. I am using Solaris and the perl version is 5.005. My C compiler is
not gcc but proprietary C package from Sun.
| |
| James Willmore 2004-04-27, 2:09 am |
| Reply-To: jwillmore@adelphia.net
MIME-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Lines: 39
NNTP-Posting-Host: 68.67.85.74
X-Trace: sv3-LXBgpquGEn7hy4ktcGh8kU/ So8Ywem1JGafu01jq+BscnIkEAfoHyRtdLd0cVPA
yVRwCkC0Fe9PwvVN!5QEaFJ9yOwBmvkWMa1VWGX2
GYIK1U4oAj2gxaNaHu30DGn6md+OqZDzbo7DPRGq
JHBvIobEspHuD!K4coEyGAt5ZCEb44knIwOHTZvU
wo2rpRsD4=
X-Complaints-To: abuse@adelphia.net
X-DMCA-Complaints-To: copyright@adelphia.net
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.1
Path: kermit!hydra.nntpserver.com!nntpserver.com!63.223.20.70!sjc1.usenetserver.com!news.usenetserver.com!border1.nntp.sjc.giganews.com!nntp.giganews.com!local1.nntp.sjc.giganews.com!nntp.adelphia.com!news.adelphia.com.POSTED!not-for-mail
Xref: kermit comp.lang.perl.misc:317126
On Mon, 26 Apr 2004 05:18:43 -0700, mike wrote:
> James Willmore <jwillmore@remove.adelphia.net> wrote in message news:<pan.2004.04.24.15.07.05.347919@remove.adelphia.net>...
[ ... ]
[color=darkred]
> i managed to solve the problem. Just need to close the handle "Writer" before
> doing the reading. I did not use DBI.pm because i have trouble installing the
> module. I am using Solaris and the perl version is 5.005. My C compiler is
> not gcc but proprietary C package from Sun.
http://sunfreeware.com/ :-)
Latest version of Perl and gcc are available.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Artistic ventures highlighted. Rob a museum.
|
|
|
|