Problem calling startup file from C # application

I am using a C # application to call a batch file that compiles and runs a java program. (This is a scraper project that grabs content from websites.) The batch file consists of the following command:

java -classpath core.jar;mysql.jar;realtouch.jar; com.parser.MainClass C:/wamp/www/C21_real2/properties http://www.realestate.com.au/realestate/agent/century+21+harbourside+neutral+bay/tzrjnd

This batch file works fine when I go to the folder and double click on the batch file. But when I call this launch file through my application using System.Diagnostics.Process

, it says:

Could not find main class com.parser.MainClass. The program will be released now.

And the command window will close in a few seconds.

I am calling a program from C # like this:

    Process batch = new Process();

    string pathtoRunFile="E:\\newFiles\\run.bat";

    batch.StartInfo.FileName = PathtoRunFile;
    batch.StartInfo.Arguments = "";

    batch.StartInfo.UseShellExecute = true;
    batch.Start();

    batch.WaitForExit();

      

Please help me as soon as possible. I'm really confused as to why this doesn't work when I call this from my application. I am not a Java developer. So is this a problem with my main Java program? If so, how to solve it? I need to run a batch file from my C # application.

The folder structure newfiles

looks like this: (contains only files)

  • core.jar
  • mysql.jar
  • realtouch.jar
  • run.bat
+2


source to share


3 answers


Set the working directory:



batch.StartInfo.WorkingDirectory = "E:\\newFiles";

      

+9


source


This is probably a path issue - the difference between where in your directory tree the caller has the current directory and where the batch file is.

To test, open a command prompt, make sure you're not in e: \ newFiles and run e: \ newFiles \ run.bat - I would expect it to work the same way.



To fix, you need to either: a) add the path to "com.parser.MainClass" or b) set the current directory in your C # application.

+2


source


You may need to make your newFiles folder the current directory so the java vm can find your files. Try adding this to your batch file:

E:
cd E:\newFiles\

      

0


source







All Articles