Problems executing Perl scripts from PHP - php

Trying to figure this out. I am trying to execute a perl script within php, using shell_exec() like so:
<?php
$output=shell_exec("./tst.pl > test.txt");
//$output=shell_exec("./tst.pl");
echo $output;
?>
It will not write output to a file using ">" filename.txt.
It will work if I execute without directing it to a filename as I can confirm this with echo.
Does this have to do with using ">"?
Permissions should be fine as I am able to run the same perl script on command line and direct to file. Any suggestions for executing this?
The output of "test.txt" will be used as input:
<?php
$data = array();
$InputFile = file("test.txt");
...
?>

It was definitely a permissions problem. Wrote the file out to /tmp and it worked fine.
<?php
$output=shell_exec("./tst.pl > /tmp/test.txt");
echo $output;
?>

Related

execute R script from php

I am trying to execute R script from Php. It works fine with the command prompt with this :
Documents\R\R-3.5.0\bin\R.exe Desktop\my_script.R
But the same is not working from PHP call using exec. Any suggestion please!
<?php
exec("Documents\R\R-3.5.0\bin\R.exe Desktop\my_script.R", $output);
print_r($output);
?>
print_r($output) displays only "Array()" no correct result ;
Those paths must be relative to the php working directory. Otherwise they must be fully specified:
Try:
$cmd = "C:\Users\YOURNAME\Documents\R\R-3.5.0\bin\Rscript.exe C:\Users\YOURNAME\Desktop\my_script.R";
exec($cmd, $output);

Problems connecting Scilab with php?

I try to use/call Scilab with php. I followed instruction form https://www.ibm.com/developerworks/library/os-php-scilab/os-php-scilab-pdf.pdf but I cant make it work. I tried listing 1 and what I got is Array (). do I need to save sci/sce file in root folder before calling them in php? is Scilab can be called directly as the instruction?
I had exactly the same problem. I use scilab 6.0.1
This code works for me :
<?php
$path = 'C:\\wamp64\\apps\\scilab-6.0.1\\bin\\';
$path_script = 'C:\\wamp64\\www\\tests\\log.sce';
$command = $path.'WScilex-cli.exe -nb -f '.$path_script;
echo $command;
exec($command, $output);
echo '<pre>';
print_r ($output);
echo '</pre>';
?>
In the log.sce file, I saw matrix on firefox web page, save file and picture on my folder.
Best regards

Run a batch file from php code

i have a batch file that contains a command to record a live stream from server, i have tried it in CMD.exe, it work fine.
I need now to run this file from php code (by a button "Record"), but i don't get any output.
please can you check my code and try to give me a solution please :
1 - the batch file code :
#echo off
vlc input stream --sout "#duplicate{dst=display,dst=std{access=file,mux=mov,dst=output file.mp4}"
#echo off
2 - the php file code:
<?php
$file = file_get_contents("C:\\wamp\\www\\CMD\\filebat.bat");
echo exec($file);
echo "Done!";
?>
3 - Another php code:
<?php
$file = file_get_contents("C:\\wamp\\www\\CMD\\filebat.bat");
$output = exec($file);
print_r($output);
?>
4 - Another php code :
<?php
echo exec('C:\\wamp\\www\\CMD\\filebat.bat');
?>
i tried these 3 php code but i don't get any output.
kindly, can you help me to find the best solution how i Run a batch file from php code ??
regards,
4.) Should work. Check php.ini/phpinfo if SAFE_MODE is OFF.
http://www.php.net/manual/en/function.exec.php

How to execute a bash file from php on a button click

Hi i m trying to execute a bash file which contains a command to run a script file. I had been trying all possible methods but nothing seem to work. I want to run the file and display the result on the web page.
the bash file contains arguments to execute the script. i tried with
system(./bashfile path);
shell_exec(./file path);
if(isset($_POST['submit'])) {
$output = shell_exec('./Users/file.sh ');
echo "<pre>$output</pre>";
but nothing happens. what other ways i could execute the .sh file, help appriciated
system(),exec(),shell_exec(),... functions might be disabled because of security.
Also on the phpinfo page of shell_exec you can find:
This function can return NULL both when an error occurs or the program produces no output. It is not possible to detect execution failures using this function. exec() should be used when access to the program exit code is required.
try:
$command = './Users/file.sh';
$output = '';
exec ( $command, $output, $return_var );
var_dump($output);
var_dump($return_var);

Compile a .php file which takes in 4 parameter from another php file?

I have a script which when compiled from the terminal passing the parameters something like this "php compile.php arg1 arg2 arg3 arg4" on the terminal starts displaying the output result which is something like 1)file created 2) file inclusion. etc.
Now I am trying to use system(php compile.php arg1 arg2 arg3 arg4) from another php file, but it will not execute the php file or will not show an output.
For example i even tried to create hello.php------
and tried using system(php hello.php); but it did not output anything on the browser.
Can anyone please help me out, I am new to php. Thanks.
make sure you react on errors from the system call. Your actual code might also help. The following example works without problems on my box.
<?php
$file = fopen('/tmp/written.php', 'w');
fwrite($file, '<?php echo "Hello from written.php\n"; ?>');
fclose($file);
echo "calling written.php\n";
if (!system('php /tmp/written.php'))
die("something wrong\n");
else
exit("all good\n");
?>

Categories