我做常规的事情:
如果execvp因为没有找到cmd而失败,我怎么能在父进程中注意到这个错误?
我想在ubuntu服务器上使用php的exec()函数.问题是,我总是得到一个错误,找不到命令.例如使用
exec("echo 123");
Run Code Online (Sandbox Code Playgroud)
版画
sh:/ echo:未找到
对我来说,当我想使用bash时,看起来php正在使用sh shell.我尝试在/ etc/passwd中更改www-data的shell,这也没有帮助.
有没有人知道问题可能来自哪里,或者我如何为php的ubuntu用户更改shell.
谢谢,蒂莫
[编辑]
也许这有助于:
我从ssh调用bash脚本作为timo,这个脚本调用一个php脚本,它使用exec.我知道,这听起来很奇怪,但它是更大的开发环境的一部分......
关键是,我不确定,exec中的脚本执行的用户.
[编辑]
到现在为止,我发现必须涉及另一个权利问题.即使我尝试从exec中调用bash脚本test.sh(通过它的完整路径!),php test.php也会说.
sh:/test.sh:找不到
是否可以设置exec($command)功能的最大执行时间?有时执行我的$command持续时间过长会在1分钟后停止并显示此错误:
致命错误:第51行的C:\ xampp\htdocs\files.php超出最长执行时间60秒
如何增加exec()命令的最大执行时间?
if (allow()) {
exec($command);
if (file_exists($file)) {
//exec($makeflv);
echo '<script language="javascript" type="text/javascript">window.top.window.aviout(1);</script>';
} else {
echo $error;
}
} else {
echo $error;
}
Run Code Online (Sandbox Code Playgroud) 我有这个c代码:
if(fork()==0){
execl("/usr/bin/fsck", "fsck", "/dev/c0d0p1s0", NULL);
}
Run Code Online (Sandbox Code Playgroud)
它调用execl运行fsck来检查文件系统/dev/c0d0p1s0.
我的问题是:我怎样才能获得返回值fsck?
我需要返回值fsck来检查文件系统是否一致.
谢谢.
在我的Java程序中,我创建了一个执行命令来运行批处理文件的进程,如下所示:
try {
File tempFile = new File("C:/Users/Public/temp.cmd");
tempFile.createNewFile();
tempFile.deleteOnExit();
setContents(tempFile, recipe.getText()); //Writes some user input to file
String cmd = "cmd /c start " + tempFile.getPath();
Process p = Runtime.getRuntime().exec(cmd);
int exitVal = p.waitFor();
refreshActionPerformed(evt);
} catch (InterruptedException ex) {
Logger.getLogger(mainFrame.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(mainFrame.class.getName()).log(Level.SEVERE, null, ex);
}
Run Code Online (Sandbox Code Playgroud)
现在,我想要发生的是命令
refreshActionPerformed(evt);
Run Code Online (Sandbox Code Playgroud)
仅在我调用的批处理文件完成执行后运行.但是现在,它在命令提示符打开后立即运行.
我该如何解决?
我只使用apache-ant而不是 ant-contrib
我有一个ant目标
<target name="stop" depends="init" >
...
</target>
Run Code Online (Sandbox Code Playgroud)
我想在其中调用exec任务.
如果变量的值HOST_NAME是all
<exec executable="${executeSSH.shell}" >
<arg value="-h ${HOST_NAME}" />
<arg value="-i ${INSTANCE}" />
<arg value="-w 10" />
<arg value="-e ${myOperation.shell} " />
<arg value=" -- " />
<arg value="${INSTANCE} ${USERNAME} ${PASSWORD}" />
</exec>
Run Code Online (Sandbox Code Playgroud)
如果变量的值HOST_NAME是anything else
<exec executable="${executeSSH.shell}">
<arg value="-h ${HOST_NAME}" />
<arg value="-i ${INSTANCE}" />
<arg value="-e ${myOperation.shell} " />
<arg value=" -- " />
<arg value="${INSTANCE} ${USERNAME} …Run Code Online (Sandbox Code Playgroud) 这是要执行的代码
cp.exec("cc -Wall /tmp/test.c -o /tmp/test", function(e, stdout, stderr) {
if (e) {
var errorstr = "Compilation failed with the following error
"+ e.message.toString()
client.send(errorstr)
console.log(e, stdout, stderr)
ee.prototype.removeAllListeners()
} else if (stderr.length > 0) {
client.send("Compilion finished with warnings\n"+ stderr + '\n')
client.send('compiled')
ee.prototype.emit('compiled')
} else {
client.send("Compilation successful")
ee.prototype.emit('compiled')
}
})
Run Code Online (Sandbox Code Playgroud)
'client'是socket.io的回调参数的参数.'ee'是EventEmitter的一个实例
来了问题.在运行代码时,回调表明该命令不成功.console.log(e,stdout,stderr)是
{ [Error: Command failed: ] killed: false, code: false, signal: undefined } '' ''
/tmp/test.c是一个有效的C代码以及检查目录/ tmp,我发现test.c的是适当的和二进制"测试" 被生成并在上壳运行,则适当地执行.所以我不明白为什么它会导致执行不成功.错误对象的信息也没有用.希望得到一些帮助/解释
情况:
我想运行一个将自己置于后台的命令.如果它更有可能,那么我将在前台运行命令并将其自己带入后台.
题:
当进程在后台运行时:我怎样才能pid使用Go?
我尝试了以下方法:
cmd := exec.Command("ssh", "-i", keyFile, "-o", "ExitOnForwardFailure yes", "-fqnNTL", fmt.Sprintf("%d:127.0.0.1:%d", port, port), fmt.Sprintf("%s@%s", serverUser, serverIP))
cmd.Start()
pid := cmd.Process.Pid
cmd.Wait()
Run Code Online (Sandbox Code Playgroud)
这会立即返回并ssh在后台运行.但这pid不是pid正在运行的ssh过程.而且,它是pid父ssh进程之前的分叉和后台.
所以,我试图在我的Laravel 5.3中运行一个python脚本.
这个功能在我的Controller里面.这只是将数据传递给我的python脚本
public function imageSearch(Request $request) {
$queryImage = 'c:\\\xampp\\\htdocs\\\identificare_api\\\public\\\gallery\\\herbs\\\query.png'; //queryImage
$trainImage = 'c:\\\xampp\\\htdocs\\\identificare_api\\\public\\\gallery\\\herbs\\\2nd.png'; //trainImage
$trainImage1 = 'c:\\\xampp\\\htdocs\\\identificare_api\\\public\\\gallery\\\herbs\\\3rd.png';
$trainImage2 = 'c:\\\xampp\\\htdocs\\\identificare_api\\\public\\\gallery\\\herbs\\\4th.jpg';
$trainImage3 = 'c:\\\xampp\\\htdocs\\\identificare_api\\\public\\\gallery\\\herbs\\\1st.jpg';
$data = array
(
array(0, $queryImage),
array(1, $trainImage),
array(3, $trainImage1),
array(5, $trainImage2),
array(7, $trainImage3),
);
$count= count($data);
$a = 1;
$string = "";
foreach( $data as $d){
$string .= $d[0] . '-' . $d[1];
if($a < $count){
$string .= ",";
}
$a++;
}
$result = shell_exec("C:\Python27\python c:\xampp\htdocs\identificare_api\app\http\controllers\ORB\orb.py " . escapeshellarg($string));
echo $result;
}
Run Code Online (Sandbox Code Playgroud)
我的python脚本是一个ORB算法,它在将火车图像与查询图像进行比较后返回最小距离及其id.所以,这是我的python脚本:
import …Run Code Online (Sandbox Code Playgroud) exec ×10
php ×3
fork ×2
go ×2
ant ×1
apache ×1
bash ×1
batch-file ×1
c ×1
c++ ×1
command ×1
execute ×1
if-statement ×1
java ×1
javascript ×1
linux ×1
node.js ×1
orb ×1
pid ×1
posix ×1
python ×1
return-value ×1
shell ×1
shell-exec ×1
ubuntu ×1