【问题标题】:Is there any way to give user input one by one to a running .exe file in php有什么方法可以将用户输入一一提供给 php 中正在运行的 .exe 文件
【发布时间】:2020-07-22 08:23:45
【问题描述】:

我想从 php 运行 .exe 文件。它一一要求用户输入。有什么办法可以做到这一点。 我尝试使用 shell_exec()、exec(),但它们没有返回预期的结果。

【问题讨论】:

  • 您好,请出示您的代码。如果没有代码,我们无法为您提供帮助,因为我们不知道在这种情况下您的逻辑是什么样的。
  • 嗨,我刚刚使用 shell_exec() 函数来运行 .exe 文件,但现在我找不到将用户输入传递给它的方法。 $output=shell_exec("file.exe");

标签: php


【解决方案1】:

我为自己的查询找到了解决方案,请在下面找到解决目的的代码:

$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file", "error.txt", "a")
);

$process = proc_open('xyz.exe', $descriptorspec, $pipes);
$input1 = "1";
if (is_resource($process)) {
print fgets($pipes[1]); // this will help you read the lines
fwrite($pipes[0], $input1."\n"); // to provide input
print fgets($pipes[1]); 
fclose($pipes[1]);
fclose($pipes[0]);
$return_value = proc_close($process);

echo "command returned $return_value\n";

} else {
echo "Resource unavailable";
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-07
    • 1970-01-01
    • 2021-12-25
    相关资源
    最近更新 更多