1

我正在开发一个 Web 应用程序来将 G 代码发送到 3dprinter。这个 3dprinter 有一个 Linux 堆栈。我可以使用以下命令在 Win 上的 Ubuntu 应用程序中创建它

ssh root@ip password python3 /usr/share/griffin/command_util.py sendgcode G28

输入后python3 /usr/share/griffin/command_util.py会返回(Cmd) type command here

我尝试在 PHP 中使用 ssh2,连接和身份验证部分工作。此外,list,cd \usr\share\griffin && list也返回与我在 windows cmd 中得到的结果相同的结果。但是在下面的代码中,在 linux stack 中运行 py 文件后,它只返回(Cmd). 什么也没发生sendgcode G28

<?php
set_include_path('C:/xampp/htdocs/phpseclib1.0.15');
include('Net/SSH2.php');

$ssh = new Net_SSH2('ip');
if (!$ssh->login('root', 'password')) {
    exit('Login Failed');
}

echo $ssh->exec('python3 /usr/share/griffin/command_util.py && sendgcode G28');
?>

Python 中的以下代码不会收到任何返回值

# 
import paramiko
# realize transport
trans = paramiko.Transport(('ip', 22))
# connection
trans.connect(username='root', password='ultimaker')

# Specify the transport of the sshclient object as the above trans
ssh = paramiko.SSHClient()
ssh._transport = trans
# execute command
stdin, stdout, stderr = ssh.exec_command('python3 /usr/share/griffin/command_util.py \n sendgcode G28')
print(stdout.read().decode())

# close connection
trans.close()

Linux 堆栈显示 sendgcode 命令未记录在案。我不明白为什么我可以在 Windows cmd 中使用它,但不能在 PHP 或 Python 中使用它。任何帮助将不胜感激!

4

1 回答 1

0

只需删除 PHP 中的 '&&' 或 Python 中的 '\n' 即可

于 2019-06-05T17:02:24.043 回答