What I'm trying to do is to run on Windows a command, that lauches putty.exe with specyfic parameters, that will start a connection and run some commands, that are in txt file on a specified in a putty session other server. I just had to run some scripts from the other server on linux, while this main script will run on windows server.
It looks a like that:
$putty_exe_path = 'C:\\putty\\putty.exe';
$linux_command_txt_file_path = 'C:\\putty\\commands_to_run_on_linux.txt';
$putty_session_name = 'puttysessionname';
$linux_user = 'root';
$linux_password = 'password';
$cmd = "\"\"".$putty_exe_path."\" -load ".$putty_session_name." -l ".$linux_user." -pw ".$linux_password." -m \"".$linux_command_txt_file_path."\"\"";
shell_exec($cmd);
And it works, but there is a problem when script on the linux, that I run using this way is running for a long time because my script is wating for output. I would like to run that command with exec()/shell_exec() or somehow on windows server and exit. I don't need the output. I need to fire and forget. I was looking for a solution but all I found is this:
> /dev/null 2>/dev/null &
but it doesn't work on windows I guess.
If you want to execute a console command in windows and don't await for its output you redirect the output to > NUL
For example , execute this in php :
var_dump(system("cmd.exe > NUL"));// will output inmediately string(0)""
var_dump(system("cmd.exe"));// will wait for the prompt result and write something like Microsoft Windows bla bla bla ...
Aditionally , if you want to know if this is really doing something, try with :
system("echo SOME TEXT > C:\SOME_FILE.txt"); // tHIS WILL Create a text file in the C disk of windows (but we dont add > NUL because there is already an output path !)
Try with it please, read more in :