Code Comments
Programming Forum and web based access to our favorite programming groups.I appologize that this is more of a shell question (tcsh) than a perl
question, but I've found that most of the really good perl guru's are fairly
decent shell wizards as well :-)
I have a c-routine that calls a perl script something like this:
system("myscript.pl arg1 arg2 > myfile.txt");
What is the easiest way to prevent "myfile.txt" from being created if the
script dies or produces no output? (It seems the shell will always create
myfile.txt, regardless)
I can think of a couple of ways offhand...
1. Within the c-routine, check for an empty file after the script is run
and remove if empty.
2. Handle the output directly from within the perl script with
open/print/close (I.E. avoid redirection)
I was hoping some shell guru out there knows a more generic approach.
Thanks,
-Dan
---
Dan Fish - seadancr@cox.net
"A -good- dive buddy will be there if you run out of air, a -great- one will
be there before you run out!"
Post Follow-up to this messageOn Tue, 26 Oct 2004, Dan Fish wrote:
> system("myscript.pl arg1 arg2 > myfile.txt");
>
> What is the easiest way to prevent "myfile.txt" from being created if
> the script dies or produces no output? (It seems the shell will always
> create myfile.txt, regardless)
Would it be enough to just delete the file if it's empty?
du myfile.txt | grep '^0' && rm myfile.txt
That seems easier than any other approach i can think of.
--
Chris Devers
Post Follow-up to this message> > On Tue, 26 Oct 2004, Dan Fish wrote: > > created if > will always > > Would it be enough to just delete the file if it's empty? > > du myfile.txt | grep '^0' && rm myfile.txt > > That seems easier than any other approach i can think of. > How about something like this, in your perl program: -z $file && unlink $file; --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.772 / Virus Database: 519 - Release Date: 10/1/2004
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.