0

I am developing a C# application wich have access to console to run the java command and execute an specific jar, but when I run the program, the executing jar file generate his files on program output, like logs and configuration, but I want to run the jar that's already in a specific folder with his files The problem is that I tried many java arguments, but the generated output files from the jar goes everytime to my Debug folder from my visual studio project Hope anyone understood me, I very confused and sorry for my english, I am brazillian For now, thanks for your support!

DJ Vickz
  • 11
  • 4

1 Answers1

2

I can only guess, because the lines of code are missing that you use to invoke the java program from within your C# program. It is also unclear what exactly you are trying to achieve. Decide between changing the "current work directory" in the child or in the main process.

child process

I assume you want to execute something like this java -jar path\to\some.jar using code similar to this:

using System.Diagnostics;
//...

ProcessStartInfo p = new ProcessStartInfo();
p.Arguments = new string[]{"-jar", "path\to\some.jar"; 
p.FileName = "java.exe";
p.WindowStyle = ProcessWindowStyle.Hidden;
p.CreateNoWindow = true;

using (Process proc = Process.Start(start))
{
     proc.WaitForExit();
}

Adapted from here

Then you can just add this line

p.WorkingDirectory = "path\to";

Adapted from here

to setup your child process covered by the p instance with a specific current work directory. This will set the current work directory for the invocation of your java child process.

main process

To setup the current work directory for the surrounding main process add this line to your program:

System.IO.Directory.SetCurrentDirectory("some\other\path");

MSDN Documentation for SetCurrentDirectory

Community
  • 1
  • 1
isaias-b
  • 2,255
  • 2
  • 25
  • 38