当前位置: 首页 > 知识库问答 >
问题:

如何使用PHP中的参数执行。exe并将输出放到txt文件中?

魏俊茂
2023-03-14
cd C:\inetpub\wwwroot\webclient\db\nucleotide
blastdbcmd -entry $gi -db $DatabaseName -outfmt %f -out $text_files_path\result.txt
$gi = 1000232109;
$cmd = "-entry $gi -db $DatabaseName -outfmt %f";
exec("C:\inetpub\wwwroot\webclient\db\nucleotide\blastdbcmd.exe $cmd" , &$output, &$return_var);
file_put_contents("$text_files_path/result.txt", $output);  //result.txt created
echo $return_var;    // 1 is printed

第2代码:

$handle = popen('C:/inetpub/wwwroot/webclient/db/nucleotide/blastdbcmd.exe 2>&1', 'w');
$cmd = "-entry $gi -db $DatabaseName -outfmt %f";
exec("$cmd" , $output);
file_put_contents("$text_files_path/mm.txt", $output); //result.txt created
echo "hello";
pclose($handle);

第3代码:

exec("C:\inetpub\wwwroot\webclient\db\nucleotide\blastdbcmd.exe -db nr -entry $gi -outfmt %f -out $text_files_path/result.txt 2>&1"); //result.txt doesn't created

第4代码:

exec("cd C:\inetpub\wwwroot\webclient\db\nucleotide && blastdbcmd.exe -db nr -entry $gi -outfmt %f -out $text_files_path/result.txt 2>&1"); //result.txt doesn't created
exec("C:\\Windows\\System32\\cmd.exe /c \"C:\inetpub\wwwroot\webclient\db\nucleotide\blastdbcmd.exe -entry $gi -db $DatabaseName -outfmt %f -out $text_files_path\result.txt\" 2>&1");  //result.txt doesn't created
$cmd = "-entry $gi -db $DatabaseName -outfmt %f";
exec("C:\inetpub\wwwroot\webclient\db\nucleotide\blastdbcmd.exe $cmd" , &$out, &$return_var);
$output = "";
echo $out;      // "Array" is printed
foreach ($out as $line) {
echo $out;      // nothing printed
echo $line;      // nothing printed
$output .= $line;
}
file_put_contents("$text_files_path/result.txt", $output);
echo $return_var // 1 is printed
exec("cd C:\\inetpub\\wwwroot\\webclient\\db\\nucleotide && blastdbcmd.exe -entry $gi -db $DatabaseName -outfmt %f 2>&1",&$out, &$return_var);

共有1个答案

姜鸿
2023-03-14

注意$out是一个数组:

exec("yourcommand.exe", $out);

$output = "";

foreach ($out as $line) {
    $output .= $line;
}

file_put_contents("C:\\Users\\MyUser\\Documents\\result.txt", $output);

编辑:

改变

exec("C:\inetpub\wwwroot\webclient\db\nucleotide\blastdbcmd.exe $cmd", 
      &$out, &$return_var);
exec("C:\inetpub\wwwroot\webclient\db\nucleotide\blastdbcmd.exe $cmd 2>&1",
      &$out, &$return_var);
 类似资料:
  • 当我向应用程序提供参数时,它不会运行。它没有争论。 请帮帮我。

  • 我有一个EXE文件,< code>addOne.exe,它不断地从控制台上的用户获得一个整数输入(不是命令行参数),并将整数1输出到控制台上。示例输出如下所示: 我正在尝试编写一个java程序,它可以: 运行 EXE 使用 从 Java 程序持续获取用户输入,并将输入到 EXE 作为控制台输入 每当 EXE 将文本输出到控制台时,请从 Java 程序打印该文本 我可以使用以下方式运行EXE: 但我

  • 问题内容: 如何将输出重定向到txt文件(在Windows平台上)? 问题答案: 如果是我,我将使用上面的David Heffernan的方法将变量写入文本文件(因为其他方法要求用户使用命令提示符)。

  • 问题内容: 我不知道如何在中执行文件。这是我正在使用的代码。它不起作用,也不打印任何内容。有什么方法可以使用命令行执行文件? 问题答案: 您可以在node.js中尝试子进程模块的execFile函数 请参阅:http : //nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_option

  • 问题内容: 有没有一种方法可以将所有打印输出保存到python中的txt文件中?可以说我的代码中有这两行,我想将打印输出保存到名为的文件中。 我希望文件包含 问题答案: 给一个关键字参数,其中参数的值是文件流。我们可以使用以下功能创建文件流: 从Python文档中有关: 所述参数必须是与对象方法; 如果不存在或,将使用。 和文档: 打开并返回相应的文件对象。如果无法打开文件,则引发。 在作为第二个

  • 问题内容: 我想使用Java程序将avi文件转换为3gp。 为此,我使用“ EM Total Video Converter命令行2.43”,其命令为 “ C:\ EM TVCC > TVCC -f E:\ TestVideo \ 01.avi -o E:\ OutputFiles \ target.3gp” 我在站点http://www.rgagnon.com/javadetails/java-