2016-04-19 11 views
-2

私はこのパスにx.exeを持っています:C:\inetpub\wwwroot\webclient\db\nucleotideと私はこのコマンドを実行したい:blastdbcmd -db nr -entry all -outfmt "%g %T"。私はPHPコードからこれを行うことができますどのようにphpコードからwin cmdを実行するには?

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

:私は、Windowsのコマンドラインで

。私がexec($cmd)またはshell_exec($cmd)はそれをするだろうが、$cmdに上記の2つのステートメントを入力する方法を知っていますか?

Edit1: コマンドの出力をテキストファイルに保存するにはどうすればよいですか? 私は3文を試してみてください。

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

,,

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

,,

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_ $ OldDatabaseFile $ NewDatabaseFile.txt生成されません。それはコマンドが実行されていないようです!

どうすればよいですか?

ありがとうございました。

+0

あなたがしようとしました[ '$ CMD = ...'](http://php.net /manual/en/language.variables.basics.php) –

+0

@Gerald Schneider cmd初回= CD .....そして2回目=コマンド自体、両方を実行する方法? – sara

+0

[マニュアルの] chdir() '(http://php.net/manual/en/function.chdir.php)を見て、2行目を実行してください – RiggsFolly

答えて

0

の3つのオプション:

あなたがパスを持つ.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\""); 
+0

編集1 – sara

+0

@サラあなたの質問をあまり編集して、答えが無効になる。それをしないで、代わりにあなたの新しい問題で新しい質問をしてください。 –

+0

私はあなたの答えを正解と記しますが、うまくいかないようです!おそらく私はそれが間違ってテストします。しかし、実際には動作しません。私の編集は私の質問と同じです。私はPHPからcmdをどのように実行し、出力をテキストファイルにするかを知る必要があります。 – sara

関連する問題