Server Specs
Windows 2008Rc2
IIS7
mysql
PHP 5.3
I have a batch file that does a mysql dump and then zips up the contents and makes it available for download in a public folder. Now i know this scripts works because it runs fine every-time i run it manually, but i can't seem to get it to work through php.
Basically I would like to just be able to call a php page that will run this batch file.
I know that exec is enabled as im able to use shell_exec to ping google.com, and i can get the output back.
I've tried with just system() and exec(), but still nothing. In some cases it looks like the page is working, but it just sits on the loading prompt.
I've searched high and low trying a million different combinations of commands, but none of them seem to work for me.
I've been reduce to trying this simple command, as i can get ping to work from this. Although when the page is called it only displays the echo statements.
<?php
echo "Starting...";
echo shell_exec("C:\inetpub\wwwroot\DBZIP2");
echo "Success!";
?>
I've also tried this, but the page just hangs on a loading screen and doesn't display the echo commands.
<?php
echo "Starting...<br><br>";
system("cmd /c START C:\inetpub\wwwroot\DBZIP2");
echo "Success!";
?>
Not really sure where to go from here. I've tried pathing the cmd.exe file, but that made no difference. Is there an easier way to do this? Another programming Language perhaps? Any help is appreciated.
Try executing using "shell_exec" with a full path to CMD.exe
<?php
echo "Starting...<br><br>";
shell_exec("c:\WINDOWS\system32\cmd.exe /c START C:\inetpub\wwwroot\DBZIP2");
echo "Success!";
?>
Related
I'm trying to use a php script for executing a shell script. However I'm having some issues apparently with the web server.
I have a bash script called switch_audio.sh. It basically changes the active audio output of the system.
I also have a script.php that runs the code below:
<?php
echo "It's working";
exec("/var/www/html/switch_audio.sh");
?>
When I execute php script.php it's working fine. However, when I try to run it on the web browser by localhost/script.php I just get as ouput the "echo" part.
I've already tried to:
remove 'exec()' from the disable functions in php.ini;
give permissions for everybody in every folder on this path from "/" to the localhost folder;
Any thoughts about it?
Simple solution: exec() returns a string, but you also have to output it to the user:
<?php
echo "It's working";
echo exec("/var/www/html/switch_audio.sh");
?>
You already said you allowed the shell function on your php.ini configuration but it seems it's not working yet... so maybe:
You didn't restarted webserver service after changes
You have somewhere other statement more restrictive... maybe ini_set in your php files.
As a reminder, be sure that you are doing well on your php.ini file, check it for this kind of statement:
disable_functions=exec,passthru,shell_exec
Maybe you can try instead of exec other similar php function like shell_exec to check if it works. Or maybe is working and not showing anything.
I have PHP v5.3.28 setup up in Internet Information Server on WIndows Server 2008. I need to run a NET VIEW command from within my index.php file and display the output. I have not found any way to make this happen. I have been trying with system(), exec(), putting it into a .cmd file and executing that using code similar to that shown below. Nothing comes out, nothing returned. I can run other simple commands such as an xcopy, but using NET.exe does not seem to work at all.
echo "<pre>";
$str=system('C:\Windows\system32\NET1.exe VIEW \\tpptra01',$rtn);
$str=system('D:\tmp\tpptra01\cpdbfiles.bat',$rtn);
$str=exec('C:\Windows\system32\NET1.exe VIEW \\tpptra01');
echo "</pre>";
Any suggestions would be greatly appreciated, I'm at a loss.
Try this,
echo "<pre>";
echo shell_exec("C:\Windows\system32\NET1.exe VIEW \\tpptra01");
echo shell_exec("D:\tmp\tpptra01\cpdbfiles.bat");
echo shell_exec("C:\Windows\system32\NET1.exe VIEW \\tpptra01");
echo "</pre>";
Am running a ruby file using php. When I run the php in the terminal it runs but the execution is a bit slow. When I run the php file on my browser results don't display. When I use a simple command for example 'ls' it runs fine in the terminal and web browser.
below is the script am using in my php file.
echo "<pre>";
$display = system('ruby /home/user/ruby-grok/examples/test.rb');
echo "</pre>";
Without seeing the contents of test.rb we can't tell you why it isn't outputting something. The file could be empty for all we know.
At the same time, you're capturing any output of the system command and storing it in $display but you're not printing that value. Is the Ruby script returning something or supposed to print it?
Again, without knowing what's in that script we can't help in any real way.
Goal:
Run a simple Rscript from a wordpress page.
I'm currently attempting to run an Rscript using exec() upon loading the page. The script creates a histogram of 100 random samples from integers 1 through 10, writes system time to title and saves figure to .png file.
Setup:
Running Wordpress install on Ubuntu EC2 micro instance
R has been successfully installed and tested through ssh
Using Exec-PHP Wordpress plugin so that PHP code can be written and executed (tested successfully)
PHP code (within wordpress Page)
<?php
echo "This is the Exec-PHP 'Hello World'\n";
echo exec("date");
?>
<?php
exec("Rscript <PATH>/test.R");
?>
<img src="<Image Location>/samplePlot.png" alt="" title="Sample R" />
Rscript - test.R
png( "<Image Location>/samplePlot.png")
hist( sample( 1:10, 100, replace = TRUE), main= Sys.time(), lwd = 5)
dev.off()
The image file loads but it is not updated, indicating the Rscript was never executed. I've isolated it down to that being the issue but unsure why that is.
How can I debug this? I don't really know any PHP but I tried the following:
<?php
exec("\usr\bin\Rscript <PATH>/test.R", $output, $result);
echo $output;
echo $result
?>
Which returns:
Array2
I was hoping to get the command line output to check for errors. Is this possible?
I would think that the problem is that you did not specify the full path to Rscript and the user running PHP/Apache just does not know where to search for it.
Update that exec command like (on Linux):
exec("/usr/bin/Rscript <PATH>/test.R");
Anyway, I would suggest installing littler for the task later and (based on that) runnning r instead of Rscript for letting things run a lot faster - if installing eg. rApache is not an option.
To get an idea of the problem try:
$e = exec("\usr\bin\Rscript <PATH>/test.R 2>&1");
var_dump($e);
If you get something like: Error in dyn.load(file, DLLpath = DLLpath, ...) ...
you probably need to update the servers dynamic libraries (try searching for libfreetype.dylib), or if your running MAMP (as I am) you need to comment (#) the two uncommented lines in: /Applications/MAMP/Library/bin/envvars
I know it is a long time since you posted the question, but I spend a lot of time with a similar problem - hopefully somebody can save some time ;)
Trying to find a good way to print without the print dialogue on my LOCAL wamp installation, in other words the printer is connected to the server.
The best (theoretical) way I have found so far seems to be using PHP's exec function, by either running a .bat that will use notepad to open and print the file or by running notepad and printing form there.
EG:
<?php
$exe_tmp = exec('E:\WebServer\www\testprint.bat');
//or
$exe_tmp = exec('c:\WINDOWS\system32\cmd.exe /c "E:\WebServer\www\MOSys\ePos\testprint.bat"');
?>
testprint.bat
NOTEPAD /P E:\WebServer\www\current_reciept.txt
Running either of these form cmd.exe works perfectly but when trying to run it using PHP's exec, when $exe_tmp is echoed, I get seemingly nothing and an output of:
E:\WebServer\www>NOTEPAD /P E:\WebServer\www\current_reciept.txt
If anyone knows why the above don't work when called from exec(); that would be very good, or if anyone knows of another way to bypass the print dialogue that would be excellent.
Cheers
Charlie
I think the answer lies here:http://technet.microsoft.com/en-us/library/cc772773(WS.10).aspx
It would result in something like this:
$exe_tmp = exec('c:\WINDOWS\system32\cmd.exe /c "print /d:\\SERVER\printer e:\WebServer\www\current_reciept.txt"');
I din't test it but according to the microsoft site it sends it directly to the queue