nysus has asked for the wisdom of the Perl Monks concerning the following question:

I'm using someone's code (SEC) for my program. I call SEC code with the require function. Just before I call SEC, I assign contents @ARGV to pass some command line arguments that SEC accepts. Here's a sample command line that I would like to pass to SEC via @ARGV:

-s -t -H -a sample.txt > sample.html

Everything up to the ">" symbol gets passed just fine but @ARGV doesn't pass the output file name, "sample.html", along. Is there a way to do what I'm attempting?

Replies are listed 'Best First'.
Re: Passing command-line arguments to a file
by Rhandom (Curate) on Apr 17, 2001 at 11:06 UTC
    This is a system question. You need to put all dangerous sequences in double quotes. The shell doesn't know which belongs where.
    -s -t -H -a sample.txt ">" sample.html
    This will let you set it into @ARGV, however, depending upon what you are trying to do, this may not be the desired result. Unless you are exec'ing with the @ARGV as arguments, the output wont be put into sample.html.
      That's the problem. SEC isn't looking for the output file in @ARGV. It relies on the shell to do the work. Sorry I wasn't more clear on this but I'm tired as hell.
Re: Passing command-line arguments to a file
by nysus (Parson) on Apr 17, 2001 at 11:28 UTC
    Ok just discovered the answer. @ARGV must be in this format:
    @ARGV = ("-s", "-t", "-H", "-a", "sample.txt", "> sample.html")

    The format I had it in, which was incorrect was:
    @ARGV = ("-s", "-t", "-H", "-a", "sample.txt", ">", "sample.html");
    I was giving the angle bracket it's own set of quotes.

      If you think you need to pass ">" and "sample.html" as arguments, it seems possible that you don't understand the concept of "I/O Redirection".

      When most modern command interpreters (AKA "shells") see foo -a -b -c > bar They take is as a directive to execute foo, passing the arguments "-a", "-b", and "-c", and arranging for foo's output to be redirected to bar. This means that foo never sees ">" or "bar". Instead, the command interpeter has connived with the operating system to open bar and arranged for foo's "standard output" to go to bar rather than the display.

      Similarly, foo < bar means that foo's "standard input" is bar, rather than the console. The command interpeter (shell) has stripped off the "<" and "bar" and has connived with the O/S to redirect foo's standard input.

      What I suspect this means for you is that you've inherited Someone Else's Code for producing HTML. The script likely writes implicitly to STDOUT. Adding "> sample.html" on the invoking command line tells the shell to direct the script's output to "sample.html".

      The simple way to tell if this is the case is to examine the code for print statements that don't specify a file handle, such as print "<h1>Hi Mom!</h1>\n";

      Update: I looked back over some of nysus's posts, and it seems pretty clear that he does understand I/O redirection. So this is off target for this thread. On target after all.

Re: Passing command-line arguments to a file
by nysus (Parson) on Apr 18, 2001 at 00:25 UTC
    Now that I'm a bit more clear-headed than I was at 3am, I'll rephrase the question:

    Does anyone know how to force a file, called with the require function, to output to a file instead of to the default, STDOUT?

Re: Passing command-line arguments to a file
by I0 (Priest) on Apr 18, 2001 at 04:34 UTC
    open STDOUT,">sample.html";