I've got a problem related to PHP exec() function and the output of HBPLUS program. When I try to run the following command "./hbplus pPDBfile.pdb" from a Linux Terminal, all works perfectly (no extension for ./hbplus is required): it creates a multiple lines output in the terminal and a pPDBfile.hb2 file. That's what I need. Instead, when I try to launch it from PHP, it gives me a "Segmentation fault" error.
$hbplus = "hbplus p1a6z.pdb"; //p1a6z.pdb is the pdb I have -> p in front is required.
exec($hbplus); //Segmentation fault.
Moreover, I tried to replace the exec() function with system(), shell_exec() and passthru() functions. Also, I tried to add
2>&1
in order to have:
$hbplus = "hbplus p1a6z.pdb 2&>1";
The result is the same.
Do you have any suggestions? Do you think the problem is related to the multiple lines output I have?
Thanks in advance.
Related
I want to use mysqldump from my php script using exec() function.
I did that in php
$com = "mysqldump --user=username --password=mypassword mydatabasename >c:\dump\test.sql";
$exec($com,$result); var_dump($result);
It always return an empty test.sql file in the specified location , and $result is always an empty array.
The thing is, when I write the same exact line in the CMD it works!
I tried using shell_exec() and the result also is empty string. I also tried adding --host=localhost , but nothing happens either.
I work on Windows local machine with Xampp server, my mysqldump is MariaDB.
why the same line works in CMD , but not from the php script?
how to get the result from the exec() function to know where my error is?
https://serverfault.com/questions/249853/does-mysqldump-return-a-status
that answer made me almost cry.
I finally goooooooot itttttt!
I added 2>c:/dump/database.err to the call, and boooooooooooooooooom it did output the error finally.
"mysqldump' is not recognized as an internal or external command,operable program or batch file."
I corrected the full path name and got it done. oh man I hate programming :(
I'm trying to run a .php script from a php file (website) and for that I'm using shell_exec function.
I have php-cli installed and the file is executable, but it's still not working.
I have read a lot of tutorials, and also some questions and answers in here but I just can't make this work.
Here is the piece of code:
shell_exec('/usr/bin/php /opt/lampp/htdocs/projects/mix/2/includes/connections/stomp_con.php');
I tried commands like shell_exec('pwd'); and shell_exec('whoami'); and they all work.
I also know that in order to run two commands we should be separated by semi-colon but this is just one. I run it in the terminal and it work.
Thanks in advance for your help
EDIT:
I var_dumped the shell_exec(); and it's showing me string(104) usr/bin/php: /opt/lampp/lib/libxml2.so.2: version LIBXML2_2.9.0' not found (required by /usr/bin/php) because I add 2>&1 in order to output STDERR
You need to provides space at the end of the file.something like this:
shell_exec("/usr/bin/php/opt/lampp/htdocs/projects/mix/2/includes/connections/stomp_con.php ");
I am executing a bunch of ssh commands with php's exec. All of them seems to work correctly except one of them:
$command = 'ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no user#127.0.0.1 "verify /md5 filename"';
exec($command, $output);
These commands are being executed on a Cisco router if that makes any difference.
The output is about 99% completed however it gets cut off at the end. I don't receive the last line at all and the second to last line always gets cut off after the 1st character. I also tried passtru and got the same results.
I've also tried adding 2>&1 to the end of the command and it made no difference. Anyone know what is going on here or have any ideas?
Here are the last 2 lines. This is what I expect:
..........Done!
verify /md5 (flash:filename) = 8743b52063cd84097a65d1633f5c74f5
I get
.
Also, running this on command line works perfectly. I have seen others with similar issues but there wasn't really any solution. This is on php 5.3.3.
I have a little more information to add to this. I created a separate script that only called the exec and this command and got the same output. This rules out any thing else in my file or the framework I'm using.
I also ran the new script from command line and it worked perfectly. Running the script in the browser however returns the bad results.
I can verify that it has something to do with how the data is being returned and those dots. The ...... must load in a way that PHP doesn't like and it thinks the command is done.
I want to execute a command in ubuntu terminal. When I directly run the command in terminal, it runs without any problem. But What I actually want to do is to execute this command via PHP.
chdir('/home/thilini/FYP/testone/bin/');
exec('./mindtct input_folder/filename output_folder/filename');
The php code I wrote is shown above. I am using ubuntu 10.10 and the LAMP configuration. chdir is working fine and I have successfully moved from /var/www/ to /home/thilini/FYP/testone/bin/ (where I have the executable mindtct). But exec is not working. (mindtct is an executable which convert the file in the input folder to another format and store it in the output_folder under the given name).
What am I doing wrong?
The problem was an issue in the path. A forward slash was missing.
If you're running below php 5.4,check "safe_mode" in your ini file.
http://www.php.net/manual/en/features.safe-mode.functions.php
You probably want
exec('./mindtct input_folder/filename output_folder/filename');
Maybe you should set error_reporting(-1) in your script so you get some errors
You want to use shell_exec(), not exec().
shell_exec() executes a command in the terminal, whereas exec() opens an application.
$results = shell_exec('./mindtct input_folder/filename output_folder/filename');
print_r($results);
This will execute the command, store it in results, and then print_r the results in array format.
http://php.net/manual/en/function.exec.php
http://php.net/manual/en/function.shell-exec.php
I have tried to use exec() with 'whoami' to check if it works and I got the result of
nt authority\system
Now I need to run a .exe file with parameters from php via exec() function.
I tried this in command prompt and it actually runs the program with given parameters. This is the example command.
NOTE the exe file gets 3 inputs (folder, file_name, report_file_nmae)
> ..\..\some_file.exe folder="C:\path_to_folder" param=1.xml report=2.xml
But when I run this command from php file:
exec('..\..\some_file.exe folder="C:\path_to_folder" param=1.xml report=2.xml');
nothing is happening. This is the first time I am using exec() function, so I am not familiar with its details. What is wrong?
I tried using:
\\ instead of \
escapeshellarg() on the directory
added "" around directory folder names
No luck
Addendum:
echo exec($command) // echos < .... why?
or
exec($command, $output);
print_r($output); // Array()
I even changed the permission on the file to full control to all users.
If I call the program from command prompt, I can see the icon appearing next to clock for a second.
But the same call from php will not even call the program.
Edit
Even exec('notepad.exe'); is not working. Something has to be done with php configurations maybe?
I already said that I was new to exec() function. After doing some more digging, I came upon 2>&1 which needs to be added at the end of command in exec().
Thanks #mattosmat for pointing it out in the comments too. I did not try this at once because you said it is a Linux command, I am on Windows.
So, what I have discovered, the command is actually executing in the back-end. That is why I could not see it actually running, which I was expecting to happen.
For all of you, who had similar problem, my advise is to use that command. It will point out all the errors and also tell you info/details about execution.
exec('some_command 2>&1', $output);
print_r($output); // to see the response to your command
Thanks for all the help guys, I appreciate it ;)
You might also try giving the full path to the binary you're trying to run. That solved my problem when trying to use ImageMagick.