dtqysxw4659 2010-08-25 15:20
浏览 27

phptelnet vs phpseclib

I am trying to connect a unix server from php and execute .exe (C language). Earlier I used phptelnet for this purpose, but now I need to shift to phpseclib due to security issues. I had 100% success rate when I use phptelnet. I could run some of the external programs like 'C' programs with arguments as input in php script. In phptelnet I use

$telnet->DoCommand('cd public_html');
$telnet->DoCommand('cd abc');
$telnet->DoCommand('demo.exe');
$telnet->DoCommand("$inputs", $result);
echo $result;

This works perfect. But now I am using phpseclib. I could connect to the unix server via ssh and execute programs in which the inputs are hard coded in the program. I am using

echo $ssh->exec('./demo.exe');

Now the problem is how to provide inputs to the program. How can I use exec() to accept arguments as inputs. For example, demo.exe is a program to add two numbers. so can I say

 echo $ssh->exec("./demo.exe, '10 20'");

Also how can I use exec() to execute multiple lnes of code in a single execution. I am a bit confused. Any inputs on this are greatly appreciated.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • doujiao2443 2010-08-25 15:31
    关注

    Where you have multiple options to commands you'd use:

     $ssh->exec("./demo.exe '10' '20'");
    

    Leave out the comma, and enclose individual parameters each. Or convert a list with $opts = implode(" ", array_map("escapeshellarg", $opts)).

    If you are using a SSH1 connection, you can only execute one command at a time. If you are connecting to a Windows server (which this looks like), then you can't have two commands on a line.

    Only for a BSD/Linux server you could use:

     $ssh->exec("cmd1 ; cmd2");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入