Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Parameter Passing - From one script to other

Reply
Thread Tools

Parameter Passing - From one script to other

 
 
codefixer@gmail.com
Guest
Posts: n/a
 
      03-23-2005
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.

 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      03-23-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      03-23-2005
(E-Mail Removed) <(E-Mail Removed)> wrote:

> 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.


--
Tad McClellan SGML consulting
(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
JJ
Guest
Posts: n/a
 
      03-23-2005
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

"Gunnar Hjalmarsson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> (E-Mail Removed) wrote:
> > 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
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl



 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      03-23-2005
[ Please type your comments *below* the quoted part(s) of the message
you are replying to. ]

JJ wrote:
> Gunnar Hjalmarsson wrote:
>> (E-Mail Removed) wrote:
>>> 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 $!;

>
> 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.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
bjhinkle@gmail.com
Guest
Posts: n/a
 
      03-23-2005
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
--------------------------------------------------------
system("myexecscrpt.pl progtorun.exe arg1 arg2...");
--------------------------------------------------------

- myexecscrpt.pl #arg1 is progtorun.exe, arg2 is arg1, etc...
------------------------------------------
exec("arg1 arg2 arg3 ......");
------------------------------------------

Well, I have no idea if that helps or not, but I tried. It seems to me
like there is a much easier way using fork() but I haven't researched
it yet.

 
Reply With Quote
 
A. Sinan Unur
Guest
Posts: n/a
 
      03-23-2005
(E-Mail Removed) wrote in news:1111613617.773105.103840
@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
 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      03-23-2005
JJ wrote:
> Gunnar Hjalmarsson wrote:
>> (E-Mail Removed) wrote:
>>> 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 $!;

>
> 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 $!;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
JJ
Guest
Posts: n/a
 
      03-23-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> [ Please type your comments *below* the quoted part(s) of the message
> you are replying to. ]
>
> JJ wrote:
> > Gunnar Hjalmarsson wrote:
> >> (E-Mail Removed) wrote:
> >>> 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 $!;

> >
> > 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.
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl



 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      03-23-2005
Please respect the netiquette as regards quoting style! Study the
posting guidelines for this group:

http://mail.augustmail.com/~tadmc/cl...uidelines.html

especially the "Use an effective followup style" section.

JJ wrote:
> 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 $!;

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameter to function not expecting parameter Mister B C Programming 8 08-26-2010 08:01 AM
How to execute a script from another script and other script does notdo busy wait. Rajat Python 3 01-08-2010 02:05 PM
RE: How to execute a script from another script and other script doesnotdo busy wait. VYAS ASHISH M-NTB837 Python 2 01-07-2010 08:18 PM
passing file data as parameter to sql server from asp script IMRAN ASP .Net 1 01-08-2006 10:23 PM
Passing value from one script on one page to another script on another page. Robert Cohen ASP General 3 07-15-2003 01:46 PM



Advertisments