Re: exec or system in windowz to stop mysql or apache fromremote (and restart them)

From: Date: Mon, 27 Nov 2000 17:07:52 +0000
Subject: Re: exec or system in windowz to stop mysql or apache fromremote (and restart them)
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-27404@lists.php.net to get a copy of this message
Hey Folks: Ignacio Vazquez-Abrams wrote: > > On Mon, 27 Nov 2000, Delbono wrote: > > > did any of you experiment EXEC or PASSTHRU or SYSTEM in windows? > > > > I tried: > > <? > > $cmd = "c:\apache\htdocs\ec.bat"; > > system($cmd, $out); > > echo $out; > > exit; > > ?> > > > > Where ec.bat is simply: > > echo "done" > > exit > > > > If I execute the exec.php file, a dos win pops up, executes the echo > > command, exits, but in the browser nothing happens. And php hangs to wait > > for something, like it is described in the manual. > > > > I read I have to pass output to a file or something but don't know how. > > I saw samples for linux, but I work with dos/win and those examples don't > > work for me (Or I'm not able to get them working) You're on the wrong track here. Here's what the manual has for syntax for system: string system (string command [, int return_var]) So, in your example, the variable $out is an integer of the return_var. I think this only applies to *nix operations. System "Returns the last line of the command output on success, and false on failure." So, you might want to try the following instead: $out = system($cmd); echo $out; > The process execution functions/commands (exec(), passthru(), system(), and > ``) don't currently work under Win32. Try using COM to have another program > execute the batch file. That's not true. I'm able to run a variety of command line programs from the program execution functions in PHP. I'm using NT 4, Apache and can switch back and forth between PHP 3 and 4. Delbono, below is an example that runs the same command under the three program execution functions. Put this test script on your machine and check it out. The behavior of each is different. Use the one that does what you want it to. Starting and stopping mysqld should be no problem. Doing the same with Apache probably wont work. Since Apache is needed to get your PHP scripts to work. <?php $Command = "dir *.htm"; echo "<pre>\n"; echo "Command to be run: $Command\n\n"; echo "\n\n=========================================================\n"; echo "EXEC()===================================================\n"; $Return = exec("$Command"); echo "\n\n----Returns----\n"; echo "$Return"; echo "\n\n\n\n=========================================================\n"; echo "PASSTHRU()===============================================\n"; $Return = passthru("$Command"); echo "\n\n----Returns----\n"; echo "$Return"; echo "\n\n\n\n=========================================================\n"; echo "SYSTEM()=================================================\n"; $Return = system("$Command"); echo "\n\n----Returns----\n"; echo "$Return"; ?> -- PHP scripts that make your job easier http://www.analysisandsolutions.com/code/ SQL Solution | Layout Solution | Form Solution T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Ave, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409

« previous php.general (#27404) next »