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

#/usr/bin/perl -w; system("C:\\WINDOWS\\System\\deltree.exe") == 0 or print STDERR "could +nt exec foo: $!"; system (deltree.exe) or print STDERR "couldnt exec foo: $!";

i need to set a switch for deltree when it executes. its a "/y"

how do i acomplish this....im a newbie i suck!

2001-04-18 Edit by Corion : Added CODE tags

Replies are listed 'Best First'.
Re: help adding a paramter to an executable i am running
by princepawn (Parson) on Apr 18, 2001 at 00:00 UTC
    Hi, first use the CODE tag like this:
    <code>
    to enclose your source code.

    I would recommend you type

    perldoc perlfunc
    and read the docs on system. But in your case:
    #!/usr/bin/perl use strict; my @args = ('C:\\WINDOWS\\System\\deltree.exe', '/y'); system @args == 0 or die "error: $!";
    should work.
Re: help adding a paramter to an executable i am running
by arturo (Vicar) on Apr 18, 2001 at 00:05 UTC

    The array @ARGV holds the arguments you've passed to the script. So it's not that hard to handle this. Just add

    my $extra_args; if ($ARGV[0] eq "/y") { $extra_args = "/y"; } system ("C:\\WINDOWS\\System\\deltree.exe $extra_args) and die "Couldn +'t delete tree: $!\n";

    That's pretty basic, though, and not terribly extensible; depending on the other features you want to add, you might step up to Getopt::Std or Getopt::Long to process command-line arguments. To extend things as they are, look into turning @ARGV into a space-separated string so you can pass a whole bunch of arguments to the deltree command. (I'll leave that up to you, as a nice learning exercise).

    Also note: die STRING is handier than print STDERR STRING. Furthermore, since you're on Windows (evidently) your #! line is nonsensical (but, in the current context, harmless).

    HTH

    Philosophy can be made out of anything. Or less -- Jerry A. Fodor