[nycphp-talk] Executing from the command line
Hans Zaunere
zaunere at yahoo.com
Mon Oct 28 11:59:51 EST 2002
--- Clay Givens <cjtotheg at artisanquest.com> wrote:
> Hello,
> I'm trying to run a program from the command line using the
> passthru() function. I'm using phptriad on an NT machine. I can get
> the passthru() function to execut basic DOS commands like "dir" etc,
> but as soon as I try to execute a program, my browser spins.
Can you tell if the program is ever getting executed? Maybe you have
some path/permission problems?
I'm not sure about NT so much, but popen() and proc_open() may work
better for you.
H
> I'm adding an extra layer even, by running the program through a c
> command line parser that I wrote. Still no good. The command line
> argument is executed, but it starts a rogue process or something
> because the programs are running in my task manager, but the browser
> never comes back.
If the program expects input from stdin or output via stderr/stdout
you'll need to write/read, otherwise it will hang with either an empty
or filled buffer. This is where popen() might be good, or better yet,
proc_open() if available.
H
>
> So this is quite a situation for me now... I'm wondering if anyone
> has
> experience running command lines from a PHP page.
>
> Thanks a lot!
> Clay
>
> For your reference, here is my php code:
>
> <?php
>
> print("Click the button to execute SilkTest locally<br>");
> print("<form action=\\"test.php\\" method=post>\
");
> print("<input type=hidden value=1 name=go>\
");
> print("<input type=submit>\
");
> print("</form>\
");
>
> if($go == 1){
> //execute local c program
> //$command = "sys_run.exe
> c://progra~1/Segue/SilkTest/partner.exe";
> //$command = "/apache/htdocs/pats/sys_run.exe
> /progra~1/Segue/SilkTest/partner.exe -r
> /apache/htdocs/pats/pats_individual_template.t > output.txt";
> $command = "/apache/htdocs/pats/sys_run.exe
> /progra~1/Segue/SilkTest/partner.exe -q -resexport -r
> /apache/htdocs/pats/pats_testplan.pln";
> //$command = "/apache/htdocs/pats/sys_run.exe
> /progra~1/Segue/SilkTest/partner.exe";
> //$command = "/apache/htdocs/pats/sys_run.exe dir"; //works
> //$return = exec($command);
> //$return = system($command);
>
> //$return = exec("c://progra~1/Segue/SilkTest/partner.exe -r
> c://apache/htdocs/pats/pats_individual_template.t");
> print("<pre>");
> passthru($command);
> print("</pre>");
> }
>
> ?>
>
> and here is my c program sys_run.c that is using a system() command
> with
> the parsed
> arguments in argv[]:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
>
> int main(int argc, char * argv[]){
> int a, b, c;
> char CmdLn[5200];
>
> if(argc < 2){
> printf("please specify a system command (with optional
> arguments) as an argument");
> return 0;
> }
>
> printf("argc = %d\
", argc);
>
> for(a=1, b=2, c=argc; b<=c; a++, b++){
> if(b == 2){
> strcpy(CmdLn, argv[a]);
> strcat(CmdLn, " ");
> }
> if( (b > 2) && (b < c) ){
> strcat(CmdLn, argv[a]);
> strcat(CmdLn, " ");
> }
> if(b == c){
> strcat(CmdLn, argv[a]);
> }
> printf("loop: CmdLn = %s\
", CmdLn);
> }
>
> //"c://progra~1/Segue/SilkTest/partner.exe -r
> c://apache/htdocs/pats/pats_individual_template.t"
>
> printf("final: CmdLn = %s\
", CmdLn);
>
> system(CmdLn);
>
> return 0;
> }
>
>
>
>
> --- Unsubscribe at http://nyphp.org/list ---
>
>
=====
Hans Zaunere
New York PHP
http://nyphp.org
hans at nyphp.org
__________________________________________________
Do you Yahoo!?
Y! Web Hosting - Let the expert host your web site
http://webhosting.yahoo.com/
More information about the talk
mailing list