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

Hi,

I've written a 2 scripts. One which calls a command called lm which runs a tool use and dumps the output into a text file. The other is meant to run the first program and then retrieve the data from that text file and output it in html.

Everything works except for the call from one script to the other. I thought that the best method to use would be System but perhaps I don't understand how it works.

would it be wrong to just put: System("test.cgi");

I tried previously to do all of this in one file but I ran into problems with environment variables because the script that calls lm worked fine when running it from an xterm but through the web browser nothing happened.

Any help would be much appreciated.


Thanx,

Max_Glink

Replies are listed 'Best First'.
Re: call another perl script
by tune (Curate) on Nov 04, 2000 at 01:16 UTC
    Why don't you rewrite your .pl script to a subroutine, and include into the caller xript? After then you can call the routine!!!

    Like

    #!/usr/bin/perl # i'm the first script require "secondscript.pl"; #do something here # e.g. create the input for the second script $output = &call_second_script_routine($input); # voila!

    You will need some rewriting, but why not?

    -- tune

RE: call another perl script
by arturo (Vicar) on Nov 04, 2000 at 00:07 UTC

    You could, if you're careful about how the other script works, use do("/path/to/other/script");

    That works roughly like a C #include, which is why you'd have to be careful.

    Or, make the cgi a shell script which calls your two perl scripts in succession (yes, that's legal, but probably wasteful as it would start the perl interpreter twice. That's why I recommend "do" first.

    But I don't see why system("/path/to/ohter/script"); would be giving you problems. Can you be more specific?

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

Re: call another perl script
by metaperl (Curate) on Nov 03, 2000 at 23:55 UTC
    Several things:
    1. The reason that the script lm may not have run from a web browser is because Apache (or whatever webserver you are using) may not be configured to run files which don't end in .cgi
    2. You call to System should system. in other words, all lowercase. Secondly, if your test.cgi script has a use CGI; perl statement in it and you are calling it via a system call, you have to set $ENV{QUERY_STRING} before the call so that test.cgi has a query string for test.cgi to parse. Otherwise (and I may be wrong here) it will simply look for input on STDIN and you will have to pipe in POST data from the first program to the second.
    3. My guess is that you want to serve the HTML output of the second script back as the result of calling the first one via a web browser? You can certainly do all of that in one file and it would save an extra fork() call. Why don't you list the two programs so that we can suggest an integrated solution.
Re: call another perl script
by roberto (Acolyte) on Nov 04, 2000 at 22:22 UTC
    I agree with tune you should implement the second script as a subroutine (much much less overhead!)
    however it seems like a path problem, try to do
    system('/full/path/to/your/script.pl');
    (maybe we could be more helpfull if you post your script)
Re: call another perl script
by Max_Glink (Initiate) on Nov 03, 2000 at 23:45 UTC
    Hi again,

    I've been playing with it and I think my problem is that I'm unable to call this comand through a browser. An argument is missing. Possibly the environment variable as I mentioned. I'm just not sure how to do that.

    thanx,

    Max_Glink