Parameter Passing - From one script to other

Discussion in 'Perl Misc' started by codefixer@gmail.com, Mar 23, 2005.

  1. Guest

    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.
     
    , Mar 23, 2005
    #1
    1. Advertising

  2. 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
     
    Gunnar Hjalmarsson, Mar 23, 2005
    #2
    1. Advertising

  3. <> 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
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 23, 2005
    #3
  4. JJ Guest

    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" <> wrote in message
    news:...
    > 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
     
    JJ, Mar 23, 2005
    #4
  5. [ Please type your comments *below* the quoted part(s) of the message
    you are replying to. ]

    JJ wrote:
    > Gunnar Hjalmarsson wrote:
    >> 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
     
    Gunnar Hjalmarsson, Mar 23, 2005
    #5
  6. Guest

    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.
     
    , Mar 23, 2005
    #6
  7. 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
     
    A. Sinan Unur, Mar 23, 2005
    #7
  8. JJ wrote:
    > Gunnar Hjalmarsson wrote:
    >> 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
     
    Gunnar Hjalmarsson, Mar 23, 2005
    #8
  9. JJ Guest

    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" <> wrote in message
    news:...
    > [ Please type your comments *below* the quoted part(s) of the message
    > you are replying to. ]
    >
    > JJ wrote:
    > > Gunnar Hjalmarsson wrote:
    > >> 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
     
    JJ, Mar 23, 2005
    #9
  10. 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.

    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
     
    Gunnar Hjalmarsson, Mar 23, 2005
    #10
  11. <> wrote:

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


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 23, 2005
    #11
  12. Guest

    > 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.
     
    , Mar 24, 2005
    #12
  13. wrote in news:1111673738.406887.95220
    @l41g2000cwc.googlegroups.com:

    "A. Sinan Unur" <> wrote in
    news:Xns9622AB095A6F7asu1cornelledu@127.0.0.1:

    [ The attribution above was missing from your post. Please don't do that.
    ]

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


    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.
     
    A. Sinan Unur, Mar 24, 2005
    #13
  14. Guest

    > 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.
     
    , Mar 24, 2005
    #14
  15. wrote:
    >> 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.


    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
     
    Jürgen Exner, Mar 24, 2005
    #15
  16. wrote:

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


    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.
     
    Brian McCauley, Mar 24, 2005
    #16
  17. wrote:

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


    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?"
     
    Chris Mattern, Mar 24, 2005
    #17
  18. On Thu, 24 Mar 2005, Chris Mattern wrote:

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


    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
     
    Alan J. Flavell, Mar 24, 2005
    #18
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?YmJzYm9i?=
    Replies:
    2
    Views:
    765
    =?Utf-8?B?YmJzYm9i?=
    Nov 24, 2006
  2. Rajat
    Replies:
    3
    Views:
    730
    Jorgen Grahn
    Jan 8, 2010
  3. VYAS ASHISH M-NTB837
    Replies:
    2
    Views:
    589
    Jan Kaliszewski
    Jan 7, 2010
  4. Mister B
    Replies:
    8
    Views:
    584
    Nick Keighley
    Aug 26, 2010
  5. Robert Cohen
    Replies:
    3
    Views:
    295
    Andrew Durstewitz
    Jul 15, 2003
Loading...

Share This Page