How to modify IIS permissions to run batch scripts in PHP? - php

I am trying to have a PHP file call a Windows batch script using
exec("runPy.bat");
I have also tried
exec("cmd /c \\server\somePath\runPy.bat");
It doesn't matter what I try, the batch script doesn't work. And I don't get any errors. After much research I found a post saying that the problem may be due to privaleges: https://stackoverflow.com/a/11613662
Can anyone show me safe/proper way to set up permissions so that I can call batch scripts in IIS? Or is it unsafe in general to do that? Using IIS8 if that helps.

To run batch, you need to use cmd, which you can call via:
system("cmd /c C:[path to file]");

Related

PHP: How to run a Batch-Script in the background [Windows]

I've got a simple question:
How can I run a batch-script in the background on a windows machine? I need to establish a database connection with MySQL over XAMPP. For this, I need to run "mysql_start.bat" and the problem is, that the following code stops executing on the exec-command of PHP (I think it waits until the script is finished).
exec("cmd /c C:\\xampp\\mysql_start.bat > tmp.txt 2>&1");
Hint: Redirecting the output isn't necessary, I just have tried it, but also didn't work.
I haven't found any other possibilties to start MySQL.
Hopefully someone can help me.
Yours Michael.
Covert your batch file into windows executable using "Bat_to_exe converter" and just give the path removing "cmd /c" as parameters to exec().
Also use exception handling methods or "die" to check if the function returns any error.

PHP exec() with CUDA

exec("fun.exe input/input.txt ");
I want to run an CUDA program in PHP,
the task is:
load data from an input.txt. (argument)
calculating.
write an output.txt.
and PHP read ouput.txt to do next task.
In server1(Apache ,Windows XP), it can run perfectly,
but in server2,3(Apache, Windows 7),the output is wrong.
The program doesn't crash and there's no any error message in the page,
it seems like something wrong during the execution.
Next I try exec the All CPU-side version (same calculation),server2,3 can run correctly.
If I exec the fun.exe(CUDA version) in server2,3 directly(double click or in command line),the program also run perfectly.
Any idea on why server2,3 can't run the program? Thanks.
First, try using the full path to the executable. Then the full path to the input file too.
If that doesn't work, then try modifying the file permissions (try with full 777 permissions, if that works then you know where your problem lies).
Try to use the entire path (windows version using backslash).

PHP shell_exec() issue

I am having an issue using the PHP function shell_exec().
I have an application which I can run from the linux command line perfectly fine. The application takes several hours to run, so I am trying to spawn a new instance using shell_exec() to manage better. However, when I run the exact same command (which works on the command line) through shell_exec(), it returns an empty string, and it doesn't look like any new processes were started. Plus it completes almost instantly. shell_exec() is suppose to wait until the command has finished correct?
I have also tried variations of exec() with the same outcome.
Does anyone have any idea what could be going on here?
There are no symbolic links or anything funky in the command: just the path to the application and a few command line parametes.
Some thing with you env
See output of env from cli (command line interface) and php script
Also see what your shell interpreter?
And does script and cli application runs from one user?
If so, se option safe_mode
Make sure the user apache is running on (probably www-data) has access to the files and that they are executable (ls -la). A simple chmod 777 [filename] would fix that.
By default PHP will timeout after 30 sec. You can disable the limit like this:
<?php
set_time_limit(0);
?>
Edit:
Also consider this: http://www.rabbitmq.com/

problem with Wget in PHP

if I run the command in shell it will download it,No error by shell
but by PHP page always it goes to if statement
I tried shell_exec and the result is the same
I really want to do it just by Wget
But if this is impossible and your solution is cURL please tell it in more details then I can find out how to code it
$flag=system('wget -P /srv/www/htdocs/didebansnort/Downloads http://www.snort.org/reg-rules/snortrules-snapshot-2900.tar.gz/myoinkcodethatmustbesecret
');
if(!$flag)
{
echo '<script>alert("please try again!")</script>';
}
If the problem is about permissions How can I fix it?
suggestion was fopen
but I have to download from command line
If you think it is possible!
here is the site
https://www.snort.org/snort-rules/#rules
well for example by rightclick on snortrules-snapshot-2904.tar.gz
I can have it
now I think it is impossible by fopen how can I make access to it?
I think solution is "just" download via command line in PHP
I don't know!
Thanks
Are you sure your PHP config allows you to execute system() and that it allows you to run it as root?
Which user is the sudo running as? Does that user have passwordless access to root (if so, why!) You really need to avoid the sudo bit, it's very probably failing. Just make sure the user PHP runs as can write to /srv/www/htdocs/didebansnort/Downloads (understanding the risks there-of) and run the wget without the sudo.
Even better, why not use one of the built in methods of PHP to get a remote file? (fopen?)

Can't run shell script from php web script

I am trying to run a shell script from a php script.
I have complete control of the environment (unix on mac), I should have all the permissions, etc. set correctly.
The web script is in /htdocs/
The shell script can be executed from anywhere so when I go to /htdocs/ in the shell, I can easily run it like this:
$ my_shellscript
.. but when my php script (which is located in htdocs) tries to call it:
shell_exec('my_shellscript');
I get nothing.
I have proven the script can be called from that location and I have temporarily granted full access to try to get it working somehow. I am going crazy, please help.
If you know of some other way of triggering a shell script via the web that would be fine.
Thanks in advance.
well i got few weeks same problem, the solution is to check if the apace has the permission to execute your script. You could also try to run the script in php cli.
Since it is a shellscript, it needs to be invoked with the path prefix. My guess is you need to do this:
shell_exec('./my_shellscript');
First thing: make sure php isn't running in Safe Mode
Next thing: Try running it with the exec() function and using the full path (e.g. /var/www/htdocs/my_shellscript)
Try doing
echo shell_exec('my_shellscript 2>&1');
which will capture the script's stderr output and print it out. If something inside the script is failing, this output would otherwise be lost when not being run interactively.

Categories