Start function

A

Alan T

I have a command line:

myUtility.exe -1 -x myUtility.xml C:\Temp\MyDoc.doc > C:\Temp\MyDoc.txt



It works fine in the command prompt (ie. DOS prompt), it converted a doc
file into test file.



However, if I run in C#:

System.Diagnostics.Process.Start("myUtility.exe", "-1 -x myUtility.xml " +
@"C:\Temp\MyDoc.doc" + " >" + @"C:\Temp\MyDoc.txt");

That failed to created a output text file.

Any idea?



I put the myUtility.exe into my C# executable directory, so it is able to
find this and also the xml file. In addition, there is no exception raised
so I think it is executed successfully.
 
D

DaanishRumani

System.Diagnostics.Process.Start("myUtility.exe", "-1 -x myUtility.xml
" +
@"C:\Temp\MyDoc.doc" +
" >" + @"C:\Temp\MyDoc.txt");
^
There isn't a space between " >" and "C:\Temp\MyDoc.txt"
it should be " > " + @"C:\Temp\MyDoc.txt");
 
A

Alan T

That's my typo.
It has a space in front of and behind the ">" in my source code but still
does not work.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Alan said:
I have a command line:

myUtility.exe -1 -x myUtility.xml C:\Temp\MyDoc.doc > C:\Temp\MyDoc.txt

It works fine in the command prompt (ie. DOS prompt), it converted a doc
file into test file.

However, if I run in C#:

System.Diagnostics.Process.Start("myUtility.exe", "-1 -x myUtility.xml " +
@"C:\Temp\MyDoc.doc" + " >" + @"C:\Temp\MyDoc.txt");

That failed to created a output text file.

Try:

System.Diagnostics.Process.Start("cmd", "/c myUtility.exe -1 -x
myUtility.xml " +
@"C:\Temp\MyDoc.doc" + " >" + @"C:\Temp\MyDoc.txt");


ARne
 
A

Alan T

Hi,

It works as followed your format.
What is the problem in my original version?

And what is the '/c' for ?
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

It works as followed your format.
What is the problem in my original version?

And what is the '/c' for ?

I belive it is cmd that supports the > redirection.

/c is something that cmd needs - we always use it. Try
read:
cmd /?

Arne
 
A

Alan T

I got a problem is I will execute this start procedure a number of times in
a loop, say 100 times,
it pops up 100 times the command windows so how do I make it invisible ?
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Alan said:
I got a problem is I will execute this start procedure a number of times in
a loop, say 100 times,
it pops up 100 times the command windows so how do I make it invisible ?

There are an overload of Start that takes a
ProcessStartInfo as argument and that has a
WindowsStyle property that can be
ProcessWindowStyle.Hidden.

Which sounds as what you want.

Arne
 
A

Alan T

Hi,

It works for me, thanks.
Now I got another problem is in my Start, that is the timing issue.

In my Start process, I am going to export data into a text file, so I need
to make sure the exported file is created and the process is finished before
I access the text file. I got an exception when I tried to access the text
file before the export is finished.

How do I know the export is finished ?
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Alan said:
Now I got another problem is in my Start, that is the timing issue.

In my Start process, I am going to export data into a text file, so I need
to make sure the exported file is created and the process is finished before
I access the text file. I got an exception when I tried to access the text
file before the export is finished.

How do I know the export is finished ?

Process has WaitForExit method.

Arne
 
A

Alan T

What should I call after

try
.....
.....
myProcess.WaitForExit();
while (!myProcess.HasExited)
{
Thread.Sleep(1000);
}
//myProcesss.Dispose();
//myProcess.Close();
except
try
//myProcesss.Dispose();
//myProcess.Close();
except
;
end;
end;
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Alan said:
What should I call after

try
.....
.....
myProcess.WaitForExit();
while (!myProcess.HasExited)
{
Thread.Sleep(1000);
}
//myProcesss.Dispose();
//myProcess.Close();
except
try
//myProcesss.Dispose();
//myProcess.Close();
except
;
end;
end;

I can not see the purpose of testing for HasExited
when calling WaitForExit.

Arne
 
A

Alan T

Now I can use the myProcess.WaitForExit() method.
My current problem is when the .exe in the myProcess is exporting data
(extract text) from one file to another file, it hangs at some files.

eg. myExe.exe file1.doc > file2.txt

I tried in cmd, it stays in the command prompt and the output file is empty,
ie 0 KB.
The memory usage in the Task Manager shows nearly my virtual memory.

I think myExe.exe cannot handle the file1.

This is the source code:

try
Process myProcess = new Process();
myProcess.StartInfo.Filename = "cmd";
myProcess.StartInfo.Arguments = "myExe.exe file1.doc > file2.txt";
myProcess.StartInfo.CreateNoWindows = true;
myProcess.StartInfo.WindowStyle = ProcessWindowsStyle.Hidden;
myProcess.Start();
myProcess.WaitForExit(5000);
myProcesss.Dispose();
except
try
myProcesss.Dispose();
except
;
end;
end;

This is what I do, just wait for 5 seconds and kills the process.
But, I found the myExe.exe still shown in the Task Manager and eats up
memory. My machine nearly hang.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Alan said:
Now I can use the myProcess.WaitForExit() method.
My current problem is when the .exe in the myProcess is exporting data
(extract text) from one file to another file, it hangs at some files.

eg. myExe.exe file1.doc > file2.txt

I tried in cmd, it stays in the command prompt and the output file is empty,
ie 0 KB.
The memory usage in the Task Manager shows nearly my virtual memory.

I think myExe.exe cannot handle the file1.
This is what I do, just wait for 5 seconds and kills the process.
But, I found the myExe.exe still shown in the Task Manager and eats up
memory. My machine nearly hang.

I really think that fixing myexe.exe is the best solution for
this problem.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top