Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I want STDOUT's filename!

Status
Not open for further replies.

darkreaper00

Technical User
Aug 5, 2002
23
US
I have a program for which the user specifies the output as an argument in the commandline -- i.e.
Code:
> filename
puts my program's output to STDOUT into a file named filename. I want to know how I can capture that name from within my program, without evaluating the arguments from the command line. Naturally, things like

Code:
$filename = *STDOUT;
$filename2 = \*STDOUT;

give me

Code:
*main::STDOUT
GLOB(0X14000ed60)

Is there a simple command to capture the filename (or "-" if lacking, right?) STDOUT points to? The big picture is the need to create multiple output files on occasion, and I want to let them be
Code:
filename_01.x, filename_02.x
, etc., if the user has supplied
Code:
filename.x
as his output file argument. I'm fine with getting there, once I can get my hands on that filename.

Thanks!
t
 
don't understand why you don't want to evaluate the command line Mike
________________________________________________________________

"Experience is the comb that Nature gives us, after we are bald."

Is that a haiku?
I never could get the hang
of writing those things.
 
personal stubbornness? I suppose I could do it the other way, and I'm probably capable of doing that already (capture ARGV[1] when ARGV[0] is > ?) but I want to figure out how to go backwards from STDOUT. Even if I wind up doing it an easier way, I'd like to know how to do things the way I was inclined to do them intuitively the first time around.

t
 
<grin> ok....

I don't know the answer, but I'll have a look. Mike
________________________________________________________________

&quot;Experience is the comb that Nature gives us, after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
I guess I don't understand. Won't

my $stdout = \*STDOUT;

give you what you want in $stdout? Then, if you do

print $stdout &quot;Some text or something\n&quot;;

won't that go to the file that STDOUT is pointing to?

What am I missing? Hardy Merrill
 
The STDOUT stream is opened at the operating systems level, hence it wouldn't be available to the program from command line arguments, nor would you be able to find out the filename of it. //Daniel
 
To clarify, I want the user to be able to type this at the command line:

Code:
process-hits < sourcefile > output.blixem

then, depending on the contents of
Code:
sourcefile
, i may want to output to multiple files, in which case i would want to name them
Code:
output_01.blixem
,
Code:
output_02.blixem
, etc. Going from
Code:
output.blixem
to
Code:
output_##.blixem
is no problem, but I would really like to get my hands on
Code:
output.blixem
, or whatever the supplied filename was -- at this rate, either evaluating the command line or asking directly, but apparently neither of those work. I presume that we can't simply ask for the whole command line, since that gets processed before it is sent to perl... What if I try to capture the filename of the file in the current directory with the most recent creation date/time? Presuming nobody fools around with such things, it should give me whatever file the user created with
Code:
> output.blixem
, right?
Code:
 
Instead of using < and > to redirect the STDIN and STDOUT, why don't you just use arguments instead? So instead of < sourcefile you could have --source-file=sourcefile and instead of > output.blixem you could have --output-file=output.blixem
That way you would be able to get the filenames and you would be sure of which file is the one that the user supplied. And maybe you would want to put the output file somewhere else than the current directory sometimes, in which case the file wouldn't be in the current directory. //Daniel
 
The shell you're running under strips the information you're looking for before Perl gets the command line at all. I don't think you can do this...

(famous last words, someone's about to prove me wrong no doubt (and good)) Mike
________________________________________________________________

&quot;Experience is the comb that Nature gives us, after we are bald.&quot;

Is that a haiku?
I never could get the hang
of writing those things.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top