Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从php代码中执行win cmd?_Php_Cmd - Fatal编程技术网

如何从php代码中执行win cmd?

如何从php代码中执行win cmd?,php,cmd,Php,Cmd,我在这个路径中有x.exe:C:\inetpub\wwwroot\webclient\db\nucleous,我想执行这个命令:blastdbcmd-db nr-entry all-outpmt”%g%T“ 在Windows命令行中,我执行以下操作: cd C:\inetpub\wwwroot\webclient\db\nucleotide blastdbcmd -db nr -entry all -outfmt "%g %T" 如何从php代码中执行此操作。我知道exec($cmd)或she

我在这个路径中有x.exe:
C:\inetpub\wwwroot\webclient\db\nucleous
,我想执行这个命令:
blastdbcmd-db nr-entry all-outpmt”%g%T“

在Windows命令行中,我执行以下操作:

cd C:\inetpub\wwwroot\webclient\db\nucleotide
blastdbcmd -db nr -entry all -outfmt "%g %T"
如何从php代码中执行此操作。我知道
exec($cmd)
shell\u exec($cmd)
会这样做,但是,如何在
$cmd
中键入上述两条语句呢

Edit1: 如何将命令的输出保存在文本文件中? 我尝试三种说法:

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);
,

,

但是,未生成NewSeq_u$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("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\"");

您是否尝试过@Gerald Schneider cmd first time=cd。。。。。第二次=命令本身,如何同时执行?请查看
chdir()
,然后运行第二次line@sara你对你的问题进行了太多的编辑,以至于答案无效。不要这样做,而是用你的新问题问一个新问题。我把你的答案标记为正确答案,但似乎不起作用!也许我测试错了。但实际上,它不起作用。我的编辑与我的问题相同。我需要知道如何从php执行cmd并将输出放在文本fle中。
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\"");