我正在尝试使用屏幕从 php 上的远程服务器运行一个冗长的命令,但我想确保屏幕在命令结束时被终止。所以我试图使用“echo $STY”来获取屏幕ID并以这种方式杀死它。出于某种原因,这不起作用。有任何想法吗:
ssh2_exec($conn, 'screen');
$getscreen =ssh2_exec($conn, 'echo $STY');
stream_set_blocking($getscreen, true);
$stream_outA = ssh2_fetch_stream($getscreen, SSH2_STREAM_STDIO);
$valA =fgets($stream_outA,160);
$scrnids =explode('.',$valA);
var_dump($scrnids);
$killcommand = 'screen -X -S '.$scrnids[0].' kill';
$stream = ssh2_exec($conn, $command);
.....
ssh2_exec($conn, $killcommand);
ssh2_exec($conn, 'exit'); //just in case
unset($conn);
var 转储只输出:
array (size=1)
0 => string '
' (length=1)