I am running a command in windows like :
command.exe > file.txt
and I get a text in the file, but when I run command.exe directly it does not shows that text on the console. The command should have outputted to stdout, but it didn't. Is there a way I can find out which stream the text goes to and read that text using php.
Thanks in advance
Running shell commands in PHP is like calling shell_exec() or any of the linked functions there. The output of the command goes to where the doc says.
For example passthru() sends the output directly to the browser.
Related
When I run the command node auth.js in my cmd tool,I get the output..I want to get the output of javascript in php file.So I tried below codes but its returning empty output
<?php
exec("node auth.js &", $output);
var_dump($output);
?>
I also tried full path.But still not working.And is it safe to use the above codes ? or is there any php class wrapper to do this job.
I seems you are telling to the shell to send in background the executable (node and its file), so the standard output will be redirect on the new forked shell instead of the one you are waiting for in your php code.
If you want to leave the program executing in background, you can redirect output to a file and then read it inside php.
Hope it was useful to you :)
I have SWI Prolog working in my vm where I'm going to be working on a PHP/HTML website. I've been following this guide: http://www.j-paine.org/dobbs/prolog_from_php.html#appendix to set up my php file to receive the output from the executed prolog file. The problem that I'm having is that it seems that the output from SWI's command line (which I'm executing from my bash terminal) isn't being captured as a standard output that I can get PHP to recognize. So, in my terminal, when I execute SWI and a test prolog file, it writes out like I need it to, but I can't figure out how to capture that output to then use in PHP.
Any ideas or suggestions would be really great. Thanks!
I want to print the output of a command named jnettop into an html file.
I am very familiar with shell_exec() and sort.
But it doesnt work as the command that Im using doesnt have a bash mode like top that is described here.
The end goal is have a site that I go to and I see the information that jnettop would normally display in terminal.
Here is the link to jnettops wiki page.
You might try passthru() or exec() with the output argument peresent.
the command that Im using doesnt have a bash mode like top
Sure it has: jnettop --display text.
I want to compare two images using Image Magick. For this I am using following command in windows command prompt
compare -verbose -metric mae image1.jpg image2.jpg difference.png
This command compares image1 and image2 and prints the resultant output to command prompt window and generates a difference.jpg file that shows difference between two images.
But when I run same command using php shell_exec() no output is returned. I know that the command is being executed by php as difference.jpg is being generated but no output is returned by the function. Similarly when i try passthrough() or system() to get output, again the command is being executed but no output is returned.But when I use builtin system commands like dir I can easily get output.
Any help will be appreciated as I am stuck on this for hours but still no success Thanks
I solved the problem. Its strange that imagemagick compare with verbose arguement does not send anything to normal command promt output. It sends output to stderr. Stderr normally receives error output. But here this command is writing normal output to stderr. As output is going to stderr so shell_exec() is unable to get it. In order to capture it in shell_exec() we will have to append 2>&1 to command. This will redirect stderr to normal command prompt output.
The ImageMagick compare command normally doesn't produce any output. You give it two input files and the name of the output file, and it quietly creates the output file.
If there's an error, it will write an error message to stderr and set a non-zero exit status. (There should be a way to get the exit status, but I don't know PHP.)
I want to send ffmpeg output to a php file so I can use a regex and update the output into a database. This will allow me to handle progress for multiple uploads. Does anyone know how to do this? Can it be done? Currently I can execute a php file with parameters after the ffmpeg command, and get ffmpeg to write to a txt file but can I send the output to the php file and execute it?
execute php file with parameters
&& php /opt/lampp/htdocs/xampp/site/update_db.php ".$parameter1." ".$parameter2.";
Write output to txt file
ffmpeg command and filepath to converted 1> /home/g/Desktop/output.txt 2>&1
Can something like this be done?
ffmpeg command and filepath to converted 1> php /opt/lampp/htdocs/xampp/site/update_db.php ".$output." 2>&1
Yes, you can read STDIN.
http://php.net/manual/en/features.commandline.io-streams.php
If it were me, I'd just execute FFMPEG from within PHP. You have a bit more flexibility that way, but I know that isn't desirable for every application.
You could use exec to call ffmpeg, then use the content of the output parameter to get returned output.
But doing so only allow you to get the output once the program execution is terminated:
If a program is started with this
function, in order for it to continue
running in the background, the output
of the program must be redirected to a
file or another output stream. Failing
to do so will cause PHP to hang until
the execution of the program ends.