I am using PHP built in server for testing and I was wondering is there a way you can hide cmd window when launching built in server using command php -S 127.0.0.1:809 -t Folder
I am currently working on Windows 10 so I need a Win solution.
not hundred percent sure on this, but you might try this one from:
What is cmd's equivalent to Bash's & (ampersand) for running a command without waiting for it to terminate?
so yours could be something like:
start /B php -S 127.0.0.1:809 -t Folder
You can create vbs script (run.vbs) and you can put this code in it
Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "cmd /C CD resource\php && php -S 127.0.0.1:809 -t HTML", 0
Set oShell = Nothing
0 in line signal for not displaying command line window.
Related
Prokka is a tool used to annotate bacterial genomes and can be installed and access using the command line in the local system or server.
So, I have downloaded Prokka using Git clone (git clone https://github.com/tseemann/prokka.git) and complied it on the CentOS (7) server along with all the dependencies with the latest version (NCBI-BLAST 2.10.1, hmmer 3.3, gnu Parallel).
In order to make a prediction server, I have created a webpage using PHP, and in that PHP file, I'm taking input from the user and passing that input to a shell file, and trying to execute that shell file using the shell_exec() function.
Here $fileName and $fn are the input from taken from the webpage.
$output = shell_exec("./path/to/shell/file/invoke.sh $script_path/$fileName $fn");
echo "<pre>$output</pre>";
invoke.sh file:
input_genome="$1";
prefix_genome="$2";
/path/to/prokka/bin/prokka $input_genome --outdir ./results/"$prefix_genome" --prefix $prefix_genome --locustag $prefix_genome --cpus 8 --kingdom Bacteria
Now, if I'm invoking Prokka (/path/to/prokka/bin/prokka) directly from the command line it's working fine and create all the files which ideally it should create. Moreover, if I'm running the shell script (invoke.sh) to invoke the Prokka (/path/to/prokka/bin/prokka) it's again working fine and generate all the files.
Expected and actual output files:
seq.faa
seq.err
seq.fna
seq.txt
seq.ffn
seq.gff
seq.tsv
seq.fsa
seq.gbk
seq.tbl
seq.log
seq.sqn
But the problem is while I'm running the PHP file from the web-browser as mentioned above to run the shell file (invoke.sh) it is running, but the Prokka command is not running properly inside the shell file and therefore not generating all of the output files.
I checked the error_log it showed me this:
[23:43:57] Will use blast to search against /home/group01/html/csspred/prokka/db/kingdom/Bacteria/sprot with 8 CPUs
[23:43:57] Running: cat \/home\/group01\/html\/csspred\/results\/01\-Nov\-23_43_779958414\/seq\/seq\.sprot\.tmp\.18401\.faa | parallel --gnu --plain -j 8 --block 3279 --recstart '>' --pipe blastp -query - -db /home/group01/html/csspred/prokka/db/kingdom/Bacteria/sprot -evalue 1e-09 -qcov_hsp_perc 80 -num_threads 1 -num_descriptions 1 -num_alignments 1 -seg no > \/home\/group01\/html\/csspred\/results\/01\-Nov\-23_43_779958414\/seq\/seq\.sprot\.tmp\.18401\.blast 2> /dev/null
[23:44:00] Could not run command: cat \/home\/group01\/html\/csspred\/results\/01\-Nov\-23_43_779958414\/seq\/seq\.sprot\.tmp\.18401\.faa | parallel --gnu --plain -j 8 --block 3279 --recstart '>' --pipe blastp -query - -db /home/group01/html/csspred/prokka/db/kingdom/Bacteria/sprot -evalue 1e-09 -qcov_hsp_perc 80 -num_threads 1 -num_descriptions 1 -num_alignments 1 -seg no > \/home\/group01\/html\/csspred\/results\/01\-Nov\-23_43_779958414\/seq\/seq\.sprot\.tmp\.18401\.blast 2> /dev/null
and generated only four files :
seq.HAMAP.hmm.tmp.12617.faa
seq.HAMAP.hmm.tmp.12617.hmmer3
seq.fna
seq.log
I even used a C file to invoke the execute a shell file which ultimately invokes the Prokka command but again the problem remained the same.
PHP: $output = shell_exec("./invoke.out $script_path/$fileName $fn");
C:
`int main(int argc, char *argv[])
{
char command[1000];
sprintf(command, "%s %s %s", "sh /home/group01/html/csspred/scripts/CSS_pred_new_additions/prokka_test.sh", argv[1], argv[2]);
system(command);
}`
What is the problem and how to solve this? I just wanted to execute my invoke.sh or invoke.out so that at the backend my Prokka command will be able to run correctly and gives me all expected output files.
I can start the default PHP server with
php -S localhost:8000 but how to stop the server? Usually with CTRL + C yes, but if i want to do it from another terminal?
starting:
nohup php -S localhost:8000 &
pid=$!
echo $pid >/var/run/php.pid
stopping
pid=$(cat /var/run/php.pid)
kill $pid
That's only an example without proper error handling
Find the process ID, and issue a kill command. On Ubuntu linux, you can use "top" command line utility to see and stop running processes.
Once you start top, use "L" to search for "php", and you'll se it's process id
Open terminal, run htop. Press / to search and type in php -S or localhost or whatever command you've entered, F3 to search for next references if needed.
Press F9 to kill the process.
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 :
more info about
Not an answer but too long for a comment
It's important to understand what > /dev/null 2>/dev/null & is doing.
In Linux/Unix operating systems, /dev/null is an emulated device for "nothing", it discards anything written to it. It, /dev/null, doesn't exist in Windows. Research more here: https://en.wikipedia.org/wiki/Null_device
In linux there are two primary streams of output when running commands, stdout and stderr. >/dev/null redirects stdout to /dev/null, 2>/dev/null redirects stderr to /dev/null and & sends the command to the background. Now you can use this to look up equivalents in Windows.
I inherited this intranet app which unzips some requested spooled reports and dumps them into a Samba folder users have access to. Here's the PHP:
$command = "$unzip_program $path_spooled/$zip_file $filename -d $target_dir";
$ssh_command = "$ssh_syscommand -i /web/live/sshkey_nopass reportuser#$archive_server \"$command\"";
$sshpipe2 = popen( $ssh_command, 'r' );
So if I echo the SSH command being run it's:
/usr/bin/ssh -i /web/live/sshkey reportuser#192.168.1.21 "/usr/bin/unzip -c /reports/spooled/2012/jan.zip 01SU7C.RPT" |
/usr/bin/ssh -i /web/live/sshkey reportuser#192.168.1.2 "cat > /reports/spooled/01SU7C.RPT"
(I inserted a carriage return after the pipe for readability)
If I execute that command from the command line it works fine. If run from php it fails with no errors.
All I need is some help working out where to look. I figure it could be a missing ssh key, but the server does show a login from that user when the command is executed.
What am I missing? Where should I look? Is there something about unzip I don't know about? Do I need to set some sort of context from Apache?
I know that it is quite easy to figure out a terminal's size parameters via the stty -a command. When using local CLI PHP scripts, there is no problem at all on grabbing that output via system() or so.
But I am trying the same thing via a php script started from an ssh command. Sadly, all that stty ever returns is:
stty: standard input: Invalid argument.
The calling code is:
exec('stty -a | head -n 1', $query);
echo $query[0];
So the question is: If I can output to the terminal and read input from it (e.g. can fread() from STDIN and fwrite() to STDOUT in PHP, shouldn't stty also have valid STDIN and STDOUT?
Use ssh -t:
% php ~/src/termtest.php
speed 9600 baud; 39 rows; 127 columns;
% ssh localhost php ~/src/termtest.php
stty: stdin isn't a terminal
% ssh -t localhost php ~/src/termtest.php
speed 9600 baud; 39 rows; 127 columns;Connection to localhost closed.
SSH does not pass in a fully functional terminal by default. Shells and ncurses seem to be able to get them somehow, but to launch something that needs one directly from SSH you need to set -t.
For the same reason you can e.g. launch tmux (or screen) by ssh'ing to a server and then typing tmux at the prompt or through ssh -t _server_ tmux but not through sh _server_ tmux.