For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > September 2004 > Executing unix commands with Perl









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Executing unix commands with Perl
Patrick V. Hull

2004-09-16, 3:56 pm

Hi,
1) Does anyone know how to write a script in perl to run a series of
executable files? I need to run a fortran program "many" times and
would like to use perl to manage the runs. I have been successful at
navigating (chdir, etc) with perl but could use a little help on
multiple runs.

2) Is it possible to write batch or input files using perl? To
perform multiple runs I need to change the input file often.

Thanks,
Patrick
Chris Cole

2004-09-16, 3:56 pm

On Thu, 16 Sep 2004 06:19:48 -0700, Patrick V. Hull wrote:

> Hi,
> 1) Does anyone know how to write a script in perl to run a series of
> executable files? I need to run a fortran program "many" times and
> would like to use perl to manage the runs. I have been successful at
> navigating (chdir, etc) with perl but could use a little help on
> multiple runs.


This is a faq. Use your perl documentation:

perldoc -f exec
perldoc -f system
perldoc -q backtick
perldoc -q external

Basically you use system("my-prog") to run the program without capturing
output from it. Or use $output = `my-prog` to run the program and capture
output.

> 2) Is it possible to write batch or input files using perl? To
> perform multiple runs I need to change the input file often.


Yes. Have a look at how you can use @ARGV to give multiple command-line
arguments.
BTW what's this got to do with cgi?
HTH
Chris.
Patrick V. Hull

2004-09-17, 8:55 pm

Chris,
I am not trying to connect any web servers only to write batch files.
The program I am using was partially written in perl so I thought I
would continue using it for a higher level control. Thanks for the
advice, so far it is working great. I do have another question. Is
it possible to save output files from within a "for" loop with names
that depend on the counter.:

such as:
log_1.dat
log_2.dat

as the loop increments?

Thanks,
Patrick


Chris Cole <ithinkiam@gmail.com> wrote in message news:<pan.2004.09.16.14.00.41.681428@gmail.com>...
> On Thu, 16 Sep 2004 06:19:48 -0700, Patrick V. Hull wrote:
>
>
> This is a faq. Use your perl documentation:
>
> perldoc -f exec
> perldoc -f system
> perldoc -q backtick
> perldoc -q external
>
> Basically you use system("my-prog") to run the program without capturing
> output from it. Or use $output = `my-prog` to run the program and capture
> output.
>
>
> Yes. Have a look at how you can use @ARGV to give multiple command-line
> arguments.
> BTW what's this got to do with cgi?
> HTH
> Chris.

Chris Cole

2004-09-17, 8:55 pm

On Fri, 17 Sep 2004 06:24:31 -0700, Patrick V. Hull wrote:

> Chris,
> I am not trying to connect any web servers only to write batch files.
> The program I am using was partially written in perl so I thought I
> would continue using it for a higher level control. Thanks for the
> advice, so far it is working great. I do have another question. Is
> it possible to save output files from within a "for" loop with names
> that depend on the counter.:
>
> such as:
> log_1.dat
> log_2.dat
>
> as the loop increments?


Sure. How about :

for (my $x = 1; $x < 10; ++$x) {
open (DATA, ">log_$x.dat") or die "Can't open file log_$x.dat: $!\n";
print DATA "stuff...";
close(DATA);
}

Like I implied before this is a perl cgi ng. If you want to ask
non-cgi perl questions you're best off going to perl.beginners or
comp.lang.perl.misc.
hth
chris
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com