shell-exec

How do I to properly handle spaces in PHP Shell_exec?

淺唱寂寞╮ 提交于 2019-12-10 05:59:19
问题 I'm running on win2003 server, PHP 526, via the cmd-line. I have a cmdline string: $cmd = ' "d:\Prog Files\foo.exe" -p "d:\data path\datadir" '; Trying to do this in php code $out = `$cmd`; # note use of backticks AKA shell_exec results in a failure by foo.exe as it interprets the -p arg as "d:\data". However, the same $cdm string copied to the windows shell cmdline executes successfully. How do I properly handle spaces in PHP shell_exec ? 回答1: Use escapeshellarg() to escape your arguments,

Unable to execute child_process.exec() when path has spaces

泄露秘密 提交于 2019-12-10 01:18:08
问题 I am using appjs * and I want to execute a command to open a folder. What I have var path = __dirname + '/folder to open/'; // path = C:\Program Files\myapplication/folder to open/ require("child_process").exec("start " + path); Error Could not find file C:\Program What I tried I already tried to escape the spaces, that didn't work. var path = __dirname + '/folder to open/'; path = path.replace(' ', '\ '); // path = C:\Program Files\myapplication/folder to open/ require("child_process").exec(

PHP - Any chance to run GUI program through exec()?

天大地大妈咪最大 提交于 2019-12-09 18:33:52
问题 i need to run a web browser (chrome - firefox ..) using exec i have tried to do it using bat file (this method mentioned here) C:\Users\farok\AppData\Local\Google\Chrome\Application\chrome.exe www.google.com when i open the file using windows every thing goes well but nothing happened when i open it using exec and i have tried to do it using jar file by BrowserControl class BrowserControl.displayURL("www.google.com"); and the same as bat file happened so is there any way to do it? note:im

shell_exec and git pull

随声附和 提交于 2019-12-09 07:22:40
问题 I was hoping someone could help, I have a PHP page which uses shell_exec to zip up a directory and run git pull to bring down recent repository changes. $op = shell_exec("cd /home/user/git/$repo/$dir/; zip -r /home/user/archives/$dir.$datestamp.zip $dir; cd /home/user/git/$repo/$dir/; git pull"); The zip works fine. If I change git pull to for example git log or git status - within my shell_exec, this works also, and I can see the log file. Just doesn't seem to like git pull. I saw another

How to execute a shell command from a php script

痞子三分冷 提交于 2019-12-09 03:05:01
问题 I would like to create a php script to execute a shell command and return its output. The server requires a private key. When I first decided to test this out I created this: <?php $command = "ls"; $output = shell_exec($command); echo "<pre>$output</pre>"; ?> That worked just fine. But when I changed $command to the command I really wanted to run: $command = "/etc/init.d/mycontrollerd status /etc/mycontrollerconfig"; it gave me this output: You need root privileges to run this script My guess

Shell_exec php with nohup

别说谁变了你拦得住时间么 提交于 2019-12-09 02:59:27
问题 I think there are tons of similar posts but I haven't yet found a solution after searching around. Basically, I'm trying to run two scripts in the background. When I run them in the commandline, I see after calling my first script: /usr/bin/nohup php script.php > nohupoutput.log & echo $! I've tried ...script.php > /dev/null & with the same result. I get: /usr/bin/nohup: ignoring input and redirecting stderr to stdout which I ignore and run the second one. I noticed that it seemed to be

Connecting to Gmail IMAP PHP “Couldn't open stream”

会有一股神秘感。 提交于 2019-12-09 02:36:46
问题 There are lots of people having similar issues but no one is answering their questions. I have IMAP enabled in PHP, Using all the correct information. I don't see where I'm going wrong. Here's my code: $hostname = '{imap.gmail.com:995/imap/ssl/novalidate-cert}'; $username = 'emailaddress@gmail.com'; $password = 'password'; $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); print_r(imap_errors()); Not returning any errors other than:

command works fine through terminal but not shell_exec php

余生颓废 提交于 2019-12-08 05:47:50
问题 Got a weird issue i have installed wav2png on my mac osx with lion now and works fine when using terminal no problem but when i try to run it using shell_exec with php like below $wav2png = shell_exec("cd {$targetDir} && /usr/bin/wav2png --foreground-color=000000ff --background-color=00000000 -o example2.png f86150f88d.wav 2>&1"); echo "<pre>" . $wav2png . "</pre>"; I get the output dyld: Library not loaded: /opt/local/lib/libpng15.15.dylib Referenced from: /usr/bin/wav2png Reason:

Loops with PHP shell_exec() : Use php for() or bash for-do-done?

岁酱吖の 提交于 2019-12-07 13:34:32
问题 Let's say I want to execute the command mycommand with PHP shell_exec() 10 times. Should I do a bash loop: shell_exec('for i in {1 .. 10} do mycommand -i done'); or rather a PHP loop: for($i = 1; $i <=10; ++$i) { shell_exec('mycommand -'.$i); } What are the reasons (security, performance, style, ...) to choose one over the other? 回答1: Go for bash loop, because shell_exec function is called only once. It will be faster than calling shell_exec multiple times. Enabling functions like exec, shell

Is using shell commands from PHP/CGI bad practice?

百般思念 提交于 2019-12-07 11:58:54
问题 Are shell commands considered a legitimate programming interface? Specifically, is there anything wrong with executing bash shell commands on a linux application server from PHP pages or CGI files? Does this introduce efficiency or security issues? Thanks 回答1: Sometimes OK, but... Sometimes it's the best way to solve a problem. But possible issues are: Security Look out for code injection if you aren't doing taint checking. Performance Running shell commands will involving forking the PHP