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>";
Related
I've got set_time_limit(0) added on one of my PHP scripts where I want the script to call an API to fetch details, which is slow.
But the PHP script wont execute after the set_time_limit(0) on my PHP installation.
To give some more information.
If I have this script
<?php
echo "Hello I am here<br>";
set_time_limit(1);
echo "Hello I am still here<br>";
It Returns
Hello I am here
Hello I am still here
If I have this
<?php
echo "Hello I am here<br>";
set_time_limit(0);
echo "Hello I am still here<br>";
It doesn't return anything but the browser keeps spinning.
I've got OSX sierra, and PHP 5.6 any help to debug would this will be great.
I found an answer, but not sure why this was happening.
I had PHP installed via brew, and a bundled version from http://php-osx.liip.ch/ was installed.
That was creating issues with the set_time_limit function. However when I switch back, and make php using the binaries the issue seem to be gone.
Still not sure whats happening in the first please.
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.
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!";
?>
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.
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