2012-01-25 7 views
4

サーバー上で、コマンドプロンプトを開き、ファイルをPDFに変換する実行可能ファイルを呼び出しようとしています。このため私はPDFCreatorオープンソースプログラムを使用しています。C#/ ASP.NET/IIS 7.5/Win7環境で実行可能なコマンドプロンプトを呼び出そうとしています

C#では私はこのコードを呼び出しています:

ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd.exe"); 
    processStartInfo.RedirectStandardInput = true; 
    processStartInfo.RedirectStandardOutput = true; 
    processStartInfo.UseShellExecute = false; 
    Process process = Process.Start(processStartInfo); 

    process.StandardInput.WriteLine(@"cd c:\program files (x86)\pdfcreator"); 
    process.StandardInput.WriteLine(@"PDFCreator.exe /PF""c:\dwf\dwf.dwf"""); 

それは何の結果が得られていない、まだ、エラーなしで実行されます。このPDFCreator.exeは、開く別のプログラムであるAutodesk Design Reviewを呼び出し、PDFドライバを使用してPDFに出力し、ファイルを保存します。あなたが見るコマンドは、私によってスタンドアロンで実行されているうまく動作します。

他のスレッドを精査することで、セキュリティが私の問題になる可能性があります。だから私はPDFCreatorとDesign Reviewフォルダ/実行可能ファイルに行き、NETWORK、NETWORK SERVICE、IIS_WPG、IIS_IUSRS、およびASP.NET Machineアカウントへの完全なアクセスを許可しました(これはおそらくセキュリティスレッドですが、問題)。これは助けにはなりません。

上記の最初のコマンドを使用してディレクトリを変更し、PDFCreatorとDesign Reviewフォルダの両方に "test123"フォルダを作成することができます。私はここに閉じ込めているようだ、どんなアイデア?

+0

ProcessStartInfo.Arguments経由で引数を提供しようとしましたか? –

+0

cmd.exeの有無にかかわらず同じ結果を試しました。 aspxページは結果またはエラーメッセージなしで実行されます。 ProcessStartInfo processStartInfo =新しいProcessStartInfo( "cmd.exe"); processStartInfo.RedirectStandardInput = true; processStartInfo.RedirectStandardOutput = true; processStartInfo.UseShellExecute = false; processStartInfo.FileName = "C:\\プログラムファイル(x86)\\ PDFCreator \\ PDFCreator.exe"; processStartInfo.Arguments = @ "/ PF" "C:\ dwf \ dwf.dwf" "/ NoStart"; プロセスプロセス=プロセス。開始(processStartInfo); – SteveCalPoly

+0

私が過去に使った手法は、コマンドの出力をログファイルにパイプする.batファイルからexeを呼び出すことです。隠されたエラーメッセージがあるかどうか確認してください。正しく報告されていないと思わないでください。 –

答えて

0

のようなものを試してみてください。私が呼び出していたアプリは、デスクトップ上に別のアプリを開いてPDFに印刷する必要があります。 [services --> service name --> log]タブで設定しない限り、IISはデスクトップ上のプログラムを開くことができません。

残念ながら、私が呼び出すアプリはサービスパネルにないので、現在はもう一度立ち往生していますが、少なくともC#の問題ではないことは分かっています。

+1

上記のserverfaultへのリンクが役立ちます。 –

0

System.Diagnostics.Processクラスには、開始されたプロセスが終了するまで待機してから、戻りコードを返すWaitForExit()というメソッドがあります。

コマンドを使用してバッチファイルを作成してから、Processクラスを使用してバッチファイルを実行してみてください。 Process.WaitForExit()を使用するとどうなりますか。あなたがProcess.Start(processInfo)を呼び出した後。 ? process.WaitForExit()の戻りコードはありますか?

2

SteveCalPolyとVal Akkapeddiのコメントは非常に興味深いものです。
とにかく、私は

/// <summary> 
    /// Executes a shell command synchronously. 
    /// </summary> 
    /// <param name="command">string command</param> 
    /// <returns>string, as output of the command.</returns> 
    public void ExecuteCommandSync(object command) 
    { 
     try 
     { 
      // create the ProcessStartInfo using "cmd" as the program to be run, 
      // and "/c " as the parameters. 
      // Incidentally, /c tells cmd that we want it to execute the command that follows, 
      // and then exit. 
      System.Diagnostics.ProcessStartInfo procStartInfo = 
       new System.Diagnostics.ProcessStartInfo("cmd", "/c " + command); 

      // The following commands are needed to redirect the standard output. 
      // This means that it will be redirected to the Process.StandardOutput StreamReader. 
      procStartInfo.RedirectStandardOutput = true; 
      procStartInfo.UseShellExecute = false; 
      // Do not create the black window. 
      procStartInfo.CreateNoWindow = true; 
      // Now we create a process, assign its ProcessStartInfo and start it 
      System.Diagnostics.Process proc = new System.Diagnostics.Process(); 
      proc.StartInfo = procStartInfo; 
      proc.Start(); 
      // Get the output into a string 
      string result = proc.StandardOutput.ReadToEnd(); 
      // Display the command output. 
      Console.WriteLine(result); 
     } 
     catch (Exception objException) 
     { 
      // Log the exception 
     } 
    } 
    /// <summary> 
    /// Execute the command Asynchronously. 
    /// </summary> 
    /// <param name="command">string command.</param> 
    public void ExecuteCommandAsync(string command) 
    { 
     try 
     { 
      //Asynchronously start the Thread to process the Execute command request. 
      Thread objThread = new Thread(new ParameterizedThreadStart(ExecuteCommandSync)); 
      //Make the thread as background thread. 
      objThread.IsBackground = true; 
      //Set the Priority of the thread. 
      objThread.Priority = ThreadPriority.AboveNormal; 
      //Start the thread. 
      objThread.Start(command); 
     } 
     catch (ThreadStartException objException) 
     { 
      // Log the exception 
     } 
     catch (ThreadAbortException objException) 
     { 
      // Log the exception 
     } 
     catch (Exception objException) 
     { 
      // Log the exception 
     } 
    } 
+0

を偽装して、これを私のコードブロックと同じ結果にしました。私はそれが許可の問題であることはほとんど確信していますが、それを追跡するためにどのログを記録するかはわかりません。イベントビューアには何もありません。コマンドプロンプトに自分自身を貼り付けると、コマンドは正常に実行されます。上記の2つの実行可能ファイルにこのプログラムのアクセス許可が与えられていないIIS 7.5アカウントがありますか? – SteveCalPoly

+0

@SteveCalPoly IISの設定を見てください。アプリケーションに設定されているアプリケーションプールの詳細設定には、使用されているユーザーアカウントの名前(私の場合はNETWORKSERVICE)があります。 –

+0

デフォルトのApplicationPoolIdentity IDを使用する "MyAppPool"という名前のアプリケーションプールを作成しました。この記事によれば、http://learn.iis.net/page.aspx/624/application-pool-identities/には、IIS AppPool \ MyAppPoolのようなプログラム実行ファイルに対するアクセス許可が設定されています。私はこれを必要に応じて行いました。 – SteveCalPoly

0

は、おそらくエラーがはStandardErrorストリームしようとしているコマンドプロンプトで実行ファイルを実行するには、次の方法を使用しますので、あなたはそれらを見ることはありませんか?

さらに、cmd.exe経由でではなくPDFCreator.exeを直接呼び出すのはなぜですか?

はserverfaultので問題をオーバー見つけたこの

ProcessStartInfo processStartInfo = new ProcessStartInfo(@"c:\program files (x86)\pdfcreator"); 
processStartInfo.Arguments = @"/PF""c:\dwf\dwf.dwf""" 
processStartInfo.RedirectStandardInput = true; 
processStartInfo.RedirectStandardOutput = true; 
processStartInfo.RedirectStandardError = true; 
processStartInfo.UseShellExecute = false; 
Process process = Process.Start(processStartInfo); 

// Read the output stream first and then wait. 
string output = p.StandardOutput.ReadToEnd(); 
p.WaitForExit(); 
string errors = p.StandardError.ReadToEnd(); 
+0

Process.Start(@ "c:\ program files(x86)\ pdfcreator \ pdfcreator.exe"、@ "/ PF" "c:\ dwf \ dwf.dwf" "/ NoStart")プロセスはタスクマネージャで実行されますが、アプリケーションは実際には開かずにタスクを完了することはありません。私もあなたのコードを試して、aspxページが無期限にロードし、文字列の出力やエラーから何も生成しません。私は先に行って、serverfaultで質問を投稿した可能性があります、彼らは私が行方不明のいくつかのセキュリティ問題を知っています。私は、Firefox.exeを呼び出すことを試みる簡単なテストを行いました、壮大なMyApplicationPoolアクセスに確かめて、それも開かないでしょう。 – SteveCalPoly

関連する問題