繁体   English   中英

如何从php代码执行win cmd?

[英]how to execute win cmd from php code?

我在此路径中有 x.exe: C:\\inetpub\\wwwroot\\webclient\\db\\nucleotide并且我想执行此命令: blastdbcmd -db nr -entry all -outfmt "%g %T"

在 Windows 命令行中,我这样做:

cd C:\inetpub\wwwroot\webclient\db\nucleotide
blastdbcmd -db nr -entry all -outfmt "%g %T"

我怎样才能从 php 代码中做到这一点。 我知道exec($cmd)shell_exec($cmd)会这样做,但是,如何在$cmd键入上述两个语句?

Edit1:如何将命令的输出保存在文本文件中? 我尝试 3 语句:

chdir("C:\\inetpub\\wwwroot\\webclient\\db\\nucleotide");
$cmd = "blastdbcmd.exe -db nr -entry all -outfmt "%g %T" -out $text_files_path/NewSeq_$OldDatabaseFile$NewDatabaseFile.txt";
exec($cmd);

,,

exec("C:\inetpub\wwwroot\webclient\db\nucleotide\blastdbcmd.exe -db nr -entry all -outfmt "%g %T" -out $text_files_path/NewSeq_$OldDatabaseFile$NewDatabaseFile.txt");

,,

exec("cd C:\inetpub\wwwroot\webclient\db\nucleotide && blastdbcmd.exe -db nr -entry all -outfmt \"%g %T\" -out $text_files_path/NewSeq_$OldDatabaseFile$NewDatabaseFile.txt");

但是,未生成 NewSeq_$OldDatabaseFile$NewDatabaseFile.txt。 好像命令没有执行!

我能做什么?

谢谢。

三个选项:

您可以在 .exe 前面加上路径:

exec("C:\inetpub\wwwroot\webclient\db\nucleotide\blastdbcmd.exe -db nr -entry all -outfmt \"%g %T\"");
// don't forget to escape the quotes.

如果您的 .exe 出于某种原因确实需要您从该目录运行它,请在执行之前使用chdir()更改为它。

chdir("C:\inetpub\wwwroot\webclient\db\nucleotide");
exec("blastdbcmd.exe -db nr -entry all -outfmt \"%g %T\"");

或者,您可以切换到目录并在一行中运行命令:

exec("cd C:\inetpub\wwwroot\webclient\db\nucleotide && blastdbcmd.exe -db nr -entry all -outfmt \"%g %T\"");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM