Parameter Passing - From one script to other

C

codefixer

Hi,

I was wondering what is the best way to send parametr from one script
to the other. I can think of using system() command. Is their any other
way to accomplish this?


Thanks.
 
G

Gunnar Hjalmarsson

I was wondering what is the best way to send parametr from one script
to the other. I can think of using system() command. Is their any other
way to accomplish this?

If it is another Perl script, you can just do:

@ARGV = qw/abc 123/;
do 'otherscript.pl' or die $!;

Or why not make the other script a module, and "use" or "require" it.

perldoc perlmod
 
T

Tad McClellan

I was wondering what is the best way to send parametr from one script
to the other. I can think of using system() command. Is their any other
way to accomplish this?


What feature or limitation of system() is it that prompts your question?

If we know why system() doesn't work for you, then we might be
able to suggest an alternative.
 
J

JJ

I tried this:
if (($value eq "I")||($value eq "U")||($value eq "PCMUP"))
{
do 'net_cov_auto.pl' or die $!;
}
It is not working. I also tried with path included. Do I miss something
here?

Thank you.

Jin
 
G

Gunnar Hjalmarsson

[ Please type your comments *below* the quoted part(s) of the message
you are replying to. ]
I tried this:
if (($value eq "I")||($value eq "U")||($value eq "PCMUP"))
{
do 'net_cov_auto.pl' or die $!;
}
It is not working.

In what way is it not working? What output did you get, and how does
that differ from what you expected?
I also tried with path included. Do I miss something
here?

It's not possible to tell only from that code snippet, which in itself
is valid Perl code.

Did you possibly miss that @ARGV is a special system variable?

perldoc perlvar

You can't just put an argument in any variable and expect it to be
available to the other script.
 
B

bjhinkle

I once wrote a Perl script that was for managing the timing of starting
other scripts. By this I mean, it started a number of other programs
(also perl scripts) on a certain time schedule.

I found that the system() command in itself was not going to work
because th system() command waits for the program that it calls to
finish. This was no good because I needed to start multiple scripts
simutaneously and the waiting part was not going to work since each
script took quite a while to run.

Then I discovered the exec() command, which essentially does the same
thing as the system() command, but instead of waiting, it terminates
the current script after starting the script I called with it.

Now, I realize that some of you Perl gurus will probably have a better
answer than what I did, but at the time I didn't think of looking for
help online. What I ended up doing was using the two commands together
to get the desired result of my main script continuing as well as the
scripts I was calling, all running at the same time. I created a
simple script that had an exec() command in it that just pushed the
arguments given to it, into the exec() command. In my main script, I
used the system() function to call the script with the exec() script.

I'm starting a new paragraph here because that was getting busy.
Anyway, the reason this fixed my problem is that the system() function
called the exec() script and waits for it. The exec() script uses the
exec() function to call the program I want to run, and then the exec()
script terminates immediately. Then the main script continues because
the system() call is now finished waiting for the exec() script.

so, basically, here's how it looks, kinda.

- main script # give program and its args as args for execscrpt
 
A

A. Sinan Unur

(e-mail address removed) wrote in @o13g2000cwo.googlegroups.com:
I once wrote a Perl script that was for managing the timing of
starting other scripts. By this I mean, it started a number of other
programs (also perl scripts) on a certain time schedule.

Why not use cron (or the equivalent of cron on the OS you were using)?

Sinan
 
G

Gunnar Hjalmarsson

JJ said:
I tried this:
if (($value eq "I")||($value eq "U")||($value eq "PCMUP"))
{
do 'net_cov_auto.pl' or die $!;
}

Btw, it struck me that do() "returns the value of the last expression
evaluated" at success (see "perldoc -f do"), so testing for a true
return value is not a reliable way to check for success. This is better:

defined( do 'net_cov_auto.pl' ) or die $!;
 
J

JJ

I actually tried to call perl program 'net_cov_auto.pl' in another perl
program which does not ask for any arguement. I put net_cov_auto.pl under
one of the path shown in %INC. But everytime I run the program, it stopped
at line do 'net_cov_auto.pl' or die $! and says "no such file or directory".
I am very new to perl and this is the first time I tried this. Thank you
very much for your help.

Jin



Gunnar Hjalmarsson said:
[ Please type your comments *below* the quoted part(s) of the message
you are replying to. ]
I tried this:
if (($value eq "I")||($value eq "U")||($value eq "PCMUP"))
{
do 'net_cov_auto.pl' or die $!;
}
It is not working.

In what way is it not working? What output did you get, and how does
that differ from what you expected?
I also tried with path included. Do I miss something
here?

It's not possible to tell only from that code snippet, which in itself
is valid Perl code.

Did you possibly miss that @ARGV is a special system variable?

perldoc perlvar

You can't just put an argument in any variable and expect it to be
available to the other script.
 
G

Gunnar Hjalmarsson

Please respect the netiquette as regards quoting style! Study the
posting guidelines for this group:

http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html

especially the "Use an effective followup style" section.
I actually tried to call perl program 'net_cov_auto.pl' in another perl
program which does not ask for any arguement. I put net_cov_auto.pl under
one of the path shown in %INC.

In %INC? You'd either put it in one of the paths of @INC, or specify the
full path:

defined( do '/full/path/to/net_cov_auto.pl' ) or die $!;
 
T

Tad McClellan

I found that the system() command in itself was not going to work
because th system() command waits for the program that it calls to
finish. This was no good because I needed to start multiple scripts
simutaneously and the waiting part was not going to work since each
script took quite a while to run.

Then I discovered the exec() command,


"exec" is the 7th word in

perldoc -f system

So I hope the discovery process did not take too long. :)

It seems to me
like there is a much easier way using fork() but I haven't researched
it yet.


Once you know that what you described is called a "daemon", it
becomes a great deal easier:

perldoc -q daemon

How do I fork a daemon process?
 
B

bjhinkle

Why not use cron (or the equivalent of
cron on the OS you were using)?

Unfortunately I wrote the program here at work where everything is
Windows. The cron "equivalent" I suppose would be Task Scheduler. I
looked into that, but TS won't schedule anything more often than to run
once a day. I needed the set of scripts to run every 4 hours. Due to
the inefficiency of big business rules and paranoia of licensing and
whatnot, I couldn't install a third party scheduler such as Kirby
Scheduler (which is a nice free one if you are stuck with Windows). So
I decided I would just write my own.
 
A

A. Sinan Unur

(e-mail address removed) wrote in @l41g2000cwc.googlegroups.com:


[ The attribution above was missing from your post. Please don't do that.
]
Unfortunately I wrote the program here at work where everything is
Windows. The cron "equivalent" I suppose would be Task Scheduler. I
looked into that, but TS won't schedule anything more often than to run
once a day. I needed the set of scripts to run every 4 hours.

Just a thought: You could schedule 6 tasks four hours apart to run every
day.

Alternatively, you could use the command line utility called "at" to
schedule the next time your script should run as the last thing you do in
your script. At the cmd prompt, type

at /?

for more information.

Sinan.
 
B

bjhinkle

Just a thought: You could schedule 6 tasks four
hours apart to run every day.

Yeah, I thought of that too, but another problem was that my program
was being written on a different version of windows than what it was
going to run on in production. I wrote the timing script so that it
would be mobile.

The idea of having multiple tasks scheduled did cross my mind though,
on a more recent project that I am still writing that needs scheduling.
But it was going to be an unreasonable amount because I need it to run
every 5 minutes all day every day (its a simple network performance
measuring tool, pings and whatnot), which would make for a lot of tasks
in the scheduler. I decided to use a free third party scheduling
program for this one.
From what I understand about the AT function, it looks like it is a
command line interface to Task Scheduler. Thanks for that information.
I can probably use that for some other programs I have on the drawing
board.
 
J

Jürgen Exner

Unfortunately I wrote the program here at work where everything is
Windows. The cron "equivalent" I suppose would be Task Scheduler. I
looked into that, but TS won't schedule anything more often than to
run once a day.

Not that this has anything to do with Perl but you may want to learn the
tools you are using before complaining about them.
MS Windows Task Scheduler allows to run a program as often as every minute.
Guess you didn't even check the "Advanced" option in the scheduling tab?

jue
 
B

Brian McCauley

Unfortunately I wrote the program here at work where everything is
Windows. The cron "equivalent" I suppose would be Task Scheduler. I
looked into that, but TS won't schedule anything more often than to run
once a day. I needed the set of scripts to run every 4 hours.

Actually it you can do that (just not via the "wizard"). You can do so
via the full UI or even the API. I routinely use TS to schedule tasks
every 5,10 or 15 minutes.

This, of course, has nothing to do with Perl.
 
C

Chris Mattern

Unfortunately I wrote the program here at work where everything is
Windows. The cron "equivalent" I suppose would be Task Scheduler. I
looked into that, but TS won't schedule anything more often than to run
once a day. I needed the set of scripts to run every 4 hours.

Then it sounds like you want to have six schedules.
--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
A

Alan J. Flavell

Then it sounds like you want to have six schedules.

It sounds like you're demonstrating the inappropriateness of
off-topic answers. "Schedule> Advanced> Repeat task" is quite
capable of specifying that a task should be run every 4 hours (or
every 10 minutes, whatever). But I'd prefer to see that answer in a
place where it's on-topic, rather than here.

all the best
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top