Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Preventing shell redirection from creating empty file
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!"


Report this thread to moderator Post Follow-up to this message
Old Post
Dan Fish
10-27-04 01:55 PM


Re: Preventing shell redirection from creating empty file
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Devers
10-28-04 08:57 PM


RE: Preventing shell redirection from creating empty file

>
> 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



Report this thread to moderator Post Follow-up to this message
Old Post
Jim
10-29-04 01:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:49 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.