Hello Everybody!Im working in linux. I have a problem for you.When the button
clicked, I execute a linux command like "mpirun" in background even my mono
program closed after button clicked. However i have a problem with ">" and
"&" command.I want to get a program standard output line by line with live
time continuosly and put it in "regcm.out" syncronusly. But now i get the
output when the standartoutput finished. And when my program closed, i can
not get the outputs at all. I want to work it in background so i want to
execute ">" and "&" commands what can i do? My code is; protected void
OnRunModelButtonClicked (object sender, EventArgs e)    {                       
SaveFile ();                                    
string regcmMPI = Tools.regCmBinPath + "regcmMPI";                      string 
CoreSelection =
CoreSelectionTextview.Buffer.Text;*                     string mpirunCode= 
(CoreSelection + "
" + regcmMPI + " " + Tools.projectPath + "XRegCM.in" + ">>regcm.log 2>&1");*    
                                        
*Tools.ExecuteOperation executer = Tools.ExecuteAsync;                  
executer.BeginInvoke("mpirun", " -np " + mpirunCode, Tools.mpirunPath,
Tools.Callback, executer);*                                             }       
                        }Tools. ExecuteAsync / Execute; public
static int Execute(string exe, string args, string workingDirectory, ref
string standartOutput, ref string standartError, bool isAsync)      {           
standartOutput = "";                    standartError = "";              
ProcessStartInfo oInfo =
new ProcessStartInfo(exe, args);                 oInfo.UseShellExecute = false; 
        
oInfo.CreateNoWindow = true;                     oInfo.RedirectStandardOutput = 
true;           
oInfo.RedirectStandardError = true;                      if(workingDirectory != 
"")                      {                       
oInfo.WorkingDirectory = workingDirectory;                       }              
                                int exitCode = -1;                              
        
try                     {                        Process proc = 
System.Diagnostics.Process.Start(oInfo);                        
proc.WaitForExit();                      exitCode = proc.ExitCode;              
                                                
System.IO.StreamReader sReader =        proc.StandardOutput;                    
         standartOutput =
sReader.ReadToEnd ();                            sReader = proc.StandardError;  
                         standartError =
sReader.ReadToEnd ();                    proc.Close();                  }       
                catch(Exception exp)                    {                       
if(!isAsync)                            {                                       
MessageBox.Show (exp.Message);                                  MessageBox.Show
(exp.StackTrace);                               }                               
else                            {                                       
standartError += "\n Exception
Message : " + exp.Message;                                      standartError 
+= "\n Exception Stack Trace :
" + exp.StackTrace;                             }                       }       
                                                                                
 return exitCode;           }



--
View this message in context: 
http://mono.1490590.n4.nabble.com/How-to-Run-Linux-Execute-Command-and-tp4659829.html
Sent from the Mono - General mailing list archive at Nabble.com.
_______________________________________________
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to