I have a .jar file which has a command line interface. I want to call the jar file through command prompt and capture the output of the Jar file.
I have tried with the exec() command.
The command I have used is:
<?php
exec('java -jar D:\\Development\\Filehandler\\dist\\Filehandler.jar \ getConfigLang', $result);
echo $result;
echo $count = count($result);
for($i=0; $i<$count;$i++){
print($result[$i]);
}
?>
The output for this was just '0 0'
Should something else be done before executing this command? like adding path etc???
I am using WAMP server.
Please help me...
Well, you can try two approaches:
1) change current directory in PHP via function http://php.net/manual/en/function.chdir.php
<?php
chdir('D:\Development\Filehandler\dist');
exec('java -jar ./Filehandler.jar \ getConfigLang', $result);
...
?>
2) change .jar file: I don't know if it is possible but try to add these additional libraries with absolute paths.
Related
I have a shell script in Linux that performs SFTP to get some files. It works fine when I execute it from a terminal.
I am trying to call the script from PHP. It seems to work until the echo, and then it doesn't do anything.
The script and the PHP file are in the same folder.
This is the PHP code:
<?php
$comando = "sh ftpgesdoc.sh";
$result=exec($comando);
echo $result;
?>
And this is shell script. When I execute from the web, I can see the echo "ejecutando sftp", but nothing happens after this point.
#!/bin/sh
echo "ejecutando sftp"
folder="/aaa/bbb"
file="xxx.PDF"
sftp UserXX#nnn.nn.n.nn << EOF
cd $folder
get $file test.pdf
EOF
exec returns only the last line from the command output. If you want to capture entire output, use proc_open. See this answer, for instance.
you have to give the full path to file
and use this 2>&1 and know the error
try something like this
$comando = "sh pathTofile/location/ftpgesdoc.sh";
if(exec("$comando 2>&1", $output, $return_var))
{
print_r($output);
echo "<br>";
print_r($return_var);
}
I am trying to download a file from a remote website. I need to run this command in command line through php. But it is not happening. Please help me.
echo $name;
$param="ftp://ftp.ebi.ac.uk/pub/databases/emdb/structures/EMD-{$name}/map/emd_{$name}.map.gz";
echo $param;
$command="wget ".escapeshellcmd($param)." -O /home/nagarjun/mercurial-1.4.1/clussym/trunk/dataset/emd{$name}.map.gz -e use_proxy=yes -e ftp_proxy=authproxy.serc.iisc.ernet.in:3128";
echo "<br />$command";
//$outputofexecutable = shell_exec($command);
passthru($command);
I can see two explanations:
wget is not found because the environment variables are not the same: use an absolute path
Your Apache (or any other webserver) user does not have permission to execute this command: you can use sudo, please see https://serverfault.com/questions/157272/allow-apache-to-run-a-command-as-a-different-user
i have this file :
~/abd.php
<?php
echo 5+5;
?>
i run this command on terminal
php5 ~/abd.php
i expect to get 10 . However, No output found.
Does it output before the prompt, e.g:
10user#server:~#
If so, try adding a newline.
I'm trying to run ffmpeg commands from php in my MAMP environment and it won't work. I've already added it to my path. I can run shell commands like whoami and ls -la with success but ffmpeg doesn't seem to work. I've also installed ffmpeg-php but it doesn't support the functions i need—Video > Image stack.
Example code:
<?php
if (shell_exec("/usr/local/bin/ffmpeg"))
{ echo "Success"; }
else
{ echo "No good"; }
?>
You should try to open the file /Applications/MAMP/Library/bin/envvars and then comment the four lines of if and else. This will looks like this:
#if test "x$DYLD_LIBRARY_PATH" != "x" ; then
# DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#else
# DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib"
It works fine for me! In my case I also setted up all project permission like 777. If you need to do this you need execute the terminal command
chmod -R 777 projectDirectory
on file htdocs directory.
I hope that you can enjoy it. Good Lucky!
1.Find the file /Applications/MAMP/Library/bin/envvars_
2.Rename this file to /Applications/MAMP/Library/bin/envvars
3.Comment all lines of this file.
4.Write this:
PATH="/Applications/MAMP/bin/php5.6.10/bin:usr/local/bin:$PATH"
export PATH
Notice: php5.6.10 - you have to write your current php version
This link on stackexchange works https://superuser.com/questions/404344/ffmpeg-works-on-terminal-not-with-php-exec
Add '2>&1' to the end of your command like this
<?php
$info = shell_exec('/usr/local/bin/ffmpeg -i '.$inputMp3Path.' 2>&1');
var_dump($info);
?>
I have a command to be run like this
$command="java -jar ".dirname(__FILE__)."\gmksplit.jar"." ".$input_path." ".$output_path;
I have echoed the $command variable and I get the output as
java -jar X:\wamp\www\moodle\gmksplit.jar X:\wamp\www\moodle/upload/maze_4.gmk X:\wamp\www\moodle/outputs/maze_4;
which is exactly I want to run..
I am trying to run it as
echo $exec($command);
it is not running. I have tried all the functions like shell_exec() and system()
It gives the output as
Java Version: 10700 (1.7.0_01)
when i run the same line in command prompt I get the output as
Java Version: 10700 (1.7.0_01)
Loading lib files in X:\wamp\www\moodle\gmksplit.jar
01_move.lgl 02_main1.lgl 03_main2.lgl 04_control.lgl
05_score.lgl 06_extra.lgl 07_draw.lgl
time taken to load file: 254 ms
so, as you see my php code is giving only the first line as output. The command is not running properly and I am not getting the intended output.
please help me
I am using the wampp server
Can you try this:
<?php
$command="java -jar ".dirname(__FILE__)."\gmksplit.jar"." ".$input_path." ".$output_path;
$out = array();
exec = ($command, $out);
print_r($out);
?>