如何在ubuntu中通过php命令打开终端?

时间:2013-09-05 07:56:44

标签: php terminal exec ubuntu-12.04 shell-exec

我已经尝试过exec,shell_exec,系统,但它们对我不起作用。

<?php
shell_exec('gnome-terminal');
?>

1 个答案:

答案 0 :(得分:0)

看起来你想通过php运行二进制文件....如果是试试这个...还要确保二进制文件具有0777权限

<?php 

//Command 
$cmd = './svdpp --training=/home/zubair/graphchi_v0.2.6/graphchi/smallnetflix_mm.train.txt --validation=/home/zubair/graphchi_v0.2.6/graphchi/smallnetflix_mm.validate.txt --binary_relevance_thresh=4 --sgd_gamma=1e-6 --max_iter=30 --quiet=1 --sgd_step_dec=0.9999 --sgd_lambda=1e-6 --D=3 --minival=1 --maxval=10';


//Binary Directory Path
$cwd = '/toolkits/collaborative_filtering/';

$descriptorspec = array (
        0 => array (
                "pipe",
                "r" 
        ),
        1 => array (
                "pipe",
                "w" 
        ),
        2 => array (
                "pipe",
                "r" 
        ) 
);

$process = proc_open ( $cmd, $descriptorspec, $pipes, $cwd );

if (is_resource ( $process )) {
    fclose ( $pipes [0] );

    echo 'Progress Output >> ' . stream_get_contents ( $pipes [1] );
    fclose ( $pipes [1] );

    echo 'Error >> ' . stream_get_contents ( $pipes [2] );
    fclose ( $pipes [2] );

    echo 'Proce_close >> '.proc_close ( $process );
}

?>