Click here to Skip to main content
15,944,401 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am trying to run a POS tagger and i m using this code

C#
private void button1_Click(object sender, EventArgs e)
{
    Process myProcess = new Process();
    
    try
    {
        myProcess.StartInfo.UseShellExecute = false;
        
        myProcess.StartInfo.FileName = "C:\\POS_Tagger\\Tagger.exe";
        myProcess.StartInfo.CreateNoWindow = true;
        myProcess.Start();
    
    }
    catch (Exception a)
    {
        textBox1.Text = a.Message;
    }

}


there is no error in this code but its not executing my file.
This file takes input from an INPUT.txt file and stores the result in RESULT.txt. Both INPUT.txt and RESULT.txt files are present in POS_Tagger folder where this Tagger.exe is also present.
Posted
Updated 16-Jan-15 23:04pm
v3
Comments
Thomas Daniels 17-Jan-15 5:02am    
Your code looks correct. How do you know Tagger.exe doesn't get executed?
rukhs 17-Jan-15 5:05am    
actually its not giving any result in RESULT.txt file. All i am getting a blank text file
Thomas Daniels 17-Jan-15 5:09am    
Are you sure Tagger.exe does what it has to do? Does it work when running it manually?
rukhs 17-Jan-15 7:11am    
yes when i am executing it manually it is giving me desired output.
rukhs 17-Jan-15 7:49am    
yup..it runs manually

comment below line and check you can see Tagger.exe running or not
C#
//myProcess.StartInfo.CreateNoWindow = true;

if it running there may be a error when processing files in Tagger.exe, if you can use message box and display error or log the errors in Tagger.exe you will able to check the error details.
note that when you execute, another exe from some other process it will take the privileges of the the process user. insufficient privileges may cause issues when dealing with file system etc...
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 17-Jan-15 5:20am    
5ed. Strictly speaking, this might be not the only reason why OP did not notice that the process was actually executing. For example, it could be the application which doesn't use any window or console.
—SA
You wrote: "Both files are present in POS_Tagger folder". Ok, but how does Tagger.exe find them? Of course, it is not hard to make it extract it's own location and use it to locate files, but it is quite possible, that it will look, in the working directory assigned to the process. You don't assingn any working directory[^], and the default is an empty string.
Try this:
C#
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = @"C:\POS_Tagger\Tagger.exe";
myProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(myProcess.StartInfo.FileName);
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();

Plus you can use Sysinternal's ProcessMonitor[^] to see if anything happens. You can also trace if the applcation is started, if it tries to open something, but fails, and so on.
 
Share this answer
 
v2
Comments
rukhs 17-Jan-15 7:47am    
when i am writing this
myProcess.StartInfo.WorkingDirectory = Path.GetDirectoryName(myProcess.StartInfo.FileName);

its giving an error:

The name Path does not exist in the current context.
Zoltán Zörgő 17-Jan-15 7:57am    
You need to use System.IO namespace.
rukhs 17-Jan-15 8:05am    
Thank you so much.. its working now. :)
Zoltán Zörgő 17-Jan-15 13:46pm    
You are welcome. But I don't understand why I got a downvote :(
rukhs 18-Jan-15 6:26am    
i am sorry... actually m new to ths.. infct i was tryng to give 5 votes but tht jst hapnd..dnt knw how to change tht. :( plz do let me knw... n sry again. its just coz of u m able to execute my code. dat was not intensional ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900