redirection failure (may be newbie question,
am 30.01.2007 18:07:18 von Deane.Rothenmaier
This is a multipart message in MIME format.
--===============1364743079==
Content-Type: multipart/alternative;
boundary="=_alternative 005E17E886257273_="
This is a multipart message in MIME format.
--=_alternative 005E17E886257273_=
Content-Type: text/plain; charset="us-ascii"
Wizards,
....Or it may be just that it's something new for me...
I'm trying to redirect the output of a file copy away from stdout so a
scheduled script won't leave a big muddy "1 file(s) copied" mess on the
(non-visible) screen. I checked in the panther book and got the suggested
redirection command,
*STDOUT = *F;
but in my code, I'm still seeing the copied message on my screen. I tried
the classic "2>&1" redirect embedded in the system call that does the
actual copying, but that didn't help either. So I must be missing
something. Here's the relevant code:
# Redirect stdout so "file(s) copied" message goes to log file, not
screen.
*STDOUT = *LOG;
# create values for $edit_file and $save_file here, then...
system( "copy \"$edit_file\" \"$save_file\" /y" );
Is it the system call itself that's keeping me from getting the desired
results?
Thanks,
Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150
"On two occasions I have been asked [by members of Parliament], 'Pray, Mr.
Babbage, if you put into the machine wrong figures, will the right answers
come out?' I am not able rightly to apprehend the kind of confusion of
ideas that could provoke such a question." -- Charles Babbage
--=_alternative 005E17E886257273_=
Content-Type: text/html; charset="us-ascii"
Wizards,
...Or it may be just that it's something new for me...
I'm trying to redirect the output of a file copy away from stdout so a scheduled script won't leave a big muddy "1 file(s) copied" mess on the (non-visible) screen. I checked in the panther book and got the suggested redirection command,
*STDOUT = *F;
but in my code, I'm still seeing the copied message on my screen. I tried the classic "2>&1" redirect embedded in the system call that does the actual copying, but that didn't help either. So I must be missing something. Here's the relevant code:
# Redirect stdout so "file(s) copied" message goes to log file, not screen.
*STDOUT = *LOG;
# create values for $edit_file and $save_file here, then...
system( "copy \"$edit_file\" \"$save_file\" /y" );
Is it the system call itself that's keeping me from getting the desired results?
Thanks,
Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150
"On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question." -- Charles Babbage
--=_alternative 005E17E886257273_=--
--===============1364743079==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============1364743079==--
Re: redirection failure (may be newbie question,
am 30.01.2007 18:44:17 von ken1
This is a multi-part message in MIME format.
--===============0232236703==
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_2517_01C7449E.A5B89F10"
This is a multi-part message in MIME format.
------=_NextPart_000_2517_01C7449E.A5B89F10
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Deane,
The construct '2>&1' won't help here - it redirects stderr to stdout, =
but there is nothing printed to stderr so it makes no difference. =
However, adding '>nul' (or more explicit, '1>nul') would do the trick, =
i.e. redirecting stdout to the 'nul' file/device. Check the return code =
from system; in my tests it correctly complains if the copy fails for =
some reason (though stupidly enough, the copy command *doesn't* write =
the error message to stderr as it should!).
$x =3D system("copy foo.txt bar.txt >nul");
print "Error: " . ($x >> 8) . "\n";
Another option is to simply use backticks (though I like the alternate =
form using 'qx') and simply disregard the output. Still have to check =
the error code. Also, this is typically not good form (why capture =
potentially a lot of output only to throw it away?).
qx("copy foo.txt bar.txt");
print "Err: " . ($? >> 8) . "\n";
Yet another option is to use the open() call to open a pipe. Similar to =
backticks/qx, but you'll have to read from the pipe (and just discard). =
Saves the memory issue with 'throw away backtick output'.
And why mess with calling an outside program/command when there's tons =
of premade modules that does copying nicely? Or make a small copy =
routine yourself, really just a few lines of code. Etc, etc.
Well, your choice :-)
HTH,
ken1
----- Original Message -----=20
From: Deane.Rothenmaier@walgreens.com=20
To: activeperl@listserv.ActiveState.com=20
Sent: Tuesday, January 30, 2007 6:07 PM
Subject: redirection failure (may be newbie question,but haven't done =
this before)
Wizards,=20
...Or it may be just that it's something new for me...=20
I'm trying to redirect the output of a file copy away from stdout so a =
scheduled script won't leave a big muddy "1 file(s) copied" mess on the =
(non-visible) screen. I checked in the panther book and got the =
suggested redirection command,=20
*STDOUT =3D *F;=20
but in my code, I'm still seeing the copied message on my screen. I =
tried the classic "2>&1" redirect embedded in the system call that does =
the actual copying, but that didn't help either. So I must be missing =
something. Here's the relevant code:=20
# Redirect stdout so "file(s) copied" message goes to log file, not =
screen.=20
*STDOUT =3D *LOG;=20
# create values for $edit_file and $save_file here, then...=20
system( "copy \"$edit_file\" \"$save_file\" /y" );
Is it the system call itself that's keeping me from getting the =
desired results?=20
Thanks,=20
Deane Rothenmaier
Systems Architect
Walgreens Corp.
847-914-5150
"On two occasions I have been asked [by members of Parliament], 'Pray, =
Mr. Babbage, if you put into the machine wrong figures, will the right =
answers come out?' I am not able rightly to apprehend the kind of =
confusion of ideas that could provoke such a question." -- Charles =
Babbage
------------------------------------------------------------ -------------=
-----
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
------=_NextPart_000_2517_01C7449E.A5B89F10
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
charset=3Diso-8859-1">
Deane,
The construct =
'2>&1'=20
won't help here - it redirects stderr to stdout, but there is nothing =
printed to=20
stderr so it makes no difference. However, adding '>nul' (or more =
explicit,=20
'1>nul') would do the trick, i.e. redirecting stdout to the 'nul'=20
file/device. Check the return code from system; in my tests it correctly =
complains if the copy fails for some reason (though stupidly enough, the =
copy=20
command *doesn't* write the error message to stderr as it =
should!).
=
$x =
system("copy foo.txt bar.txt >nul");
=
print=20
"Error: " . ($x >> 8) . "\n";
Another option is to =
simply use=20
backticks (though I like the alternate form using 'qx') and simply =
disregard the=20
output. Still have to check the error code. Also, this is typically not =
good=20
form (why capture potentially a lot of output only to throw it=20
away?).
=
qx("copy=20
foo.txt bar.txt");
print "Err: " . ($? >> 8) =
..=20
"\n";
Yet another option =
is to use the=20
open() call to open a pipe. Similar to backticks/qx, but you'll have to =
read=20
from the pipe (and just discard). Saves the memory issue with 'throw =
away=20
backtick output'.
And why mess with =
calling an=20
outside program/command when there's tons of premade modules that does =
copying=20
nicely? Or make a small copy routine yourself, really just a few lines =
of code.=20
Etc, etc.
Well, your choice=20
:-)
HTH,
ken1
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
----- Original Message -----
style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black">From:=20
=
href=3D"mailto:Deane.Rothenmaier@walgreens.com">Deane.Rothen maier@walgree=
ns.com=20
To:
title=3Dactiveperl@listserv.ActiveState.com=20
=
href=3D"mailto:activeperl@listserv.ActiveState.com">activepe rl@listserv.A=
ctiveState.com=20
Sent: Tuesday, January 30, 2007 =
6:07=20
PM
Subject: redirection failure =
(may be=20
newbie question,but haven't done this before)
Wizards, =
face=3Dsans-serif size=3D2>...Or it may be just that it's something =
new for=20
me...
I'm trying to =
redirect the=20
output of a file copy away from stdout so a scheduled script won't =
leave a big=20
muddy "1 file(s) copied" mess on the (non-visible) screen. I checked =
in the=20
panther book and got the suggested redirection command, =
face=3Dsans-serif size=3D2> *STDOUT =3D *F;
face=3Dsans-serif size=3D2>but in my code, I'm still seeing the copied =
message on=20
my screen. I tried the classic "2>&1" redirect embedded in the =
system=20
call that does the actual copying, but that didn't help either. So I =
must be=20
missing something. Here's the relevant code:
face=3D"Courier New" size=3D2> # Redirect stdout so =
"file(s) copied"=20
message goes to log file, not screen.
New"=20
size=3D2> *STDOUT =3D *LOG;
face=3D"Courier New"=20
size=3D2> # create values for $edit_file and $save_file =
here,=20
then...
=
system(=20
"copy \"$edit_file\" \"$save_file\" /y" );
face=3Dsans-serif=20
size=3D2>
Is it =
the system call=20
itself that's keeping me from getting the desired results?=20
Thanks,
face=3Dsans-serif size=3D2>Deane Rothenmaier
Systems =
Architect
Walgreens=20
Corp.
847-914-5150
"On two occasions I have been asked [by =
members=20
of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong =
figures,=20
will the right answers come out?' I am not able rightly to apprehend =
the kind=20
of confusion of ideas that could provoke such a question." -- Charles=20
Babbage
_______________________________________________
ActivePerl =
mailing=20
list
ActivePerl@listserv.ActiveState.com
To unsubscribe:=20
=
http://listserv.ActiveState.com/mailman/mysubs=
------=_NextPart_000_2517_01C7449E.A5B89F10--
--===============0232236703==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0232236703==--