Preventing shell redirection from creating empty file

From: Dan Fish (daf_at_ninemoons.com)
Date: 10/27/04


To: "Perl Beginners List" <beginners@perl.org>
Date: Tue, 26 Oct 2004 22:25:55 -0700

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


Relevant Pages

  • Re: sharing variables-data perl-asp
    ... Also how do you invoke a perl script from an active server page? ... ASP in Perl. ... Why do you want to shell out to perl when you're already running perl? ...
    (comp.lang.perl.misc)
  • Re: Command line fed to Perl was Re: File::Find again
    ... entered into a shell, such command line being passed to Perl. ... without going through a shell in order to run the Perl script. ...
    (perl.beginners)
  • Re: Setting environment variables from a Perl script
    ... >> to set environment variables in Perl scripts and make them last even ... The environment variable changes stick! ... > variables in the shell from which you started your program. ... Perl script are no longer there), but there are times when a user ...
    (comp.lang.perl.misc)
  • newbie, what is the best way to include common settings.conf values
    ... What is the best way to include common settings/values into a perl script? ... How can I do this in Perl? ... at the moment I am using a common shell file to hold these values as ...
    (comp.lang.perl.misc)
  • Re: Unexpected result from grep
    ... I'd worry about whether I should be using the shell at all. ... as big a deal as Perl. ... Most people can puzzle out even a complicated shell script and also ... seem to prefer ksh and it sure seems like a better shell to me. ...
    (comp.unix.tru64)