• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Java code issue. Please provide some insight (Posted in Software too)

dabuddha

Lifer
Sorry for posting here but I need some quick "advice" on what's going wrong here:

I'm trying to get this program to work. It does various things but the problem that im running into is that I need it to run 2 different unix scripts. Here is one method:

private void extractData(String Id, String extractFileName)
{
Runtime runtime = Runtime.getRuntime();

EnvHelper envHelper = new EnvHelper();

String commandString = dirString + "/run_extract " + Id + " " + extractFileName;
// System.out.println(header + "making system call:" + commandString + ":&quot😉;
try
{
Process process = runtime.exec(commandString);
}
catch(IOException e)
{
e.printStackTrace();
}

}
This works fine

then a few lines later, I run this method:
private void sendXml(String xmlFileName, String Id)
{

Runtime runtime = Runtime.getRuntime();
String productId = "1";

EnvHelper envHelper = new EnvHelper();

String dirString = envHelper.getProperty("BIN_DIR&quot😉;
String commandString = dirString + "/run_data_sender " + xmlFileName + " " + Id;

System.out.println("making system call:" + commandString + ":&quot😉;

try
{
Process process = runtime.exec(commandString);
}
catch(IOException e)
{
e.printStackTrace();
}

return;
}
It prints out the system call and I can run the system call manually. But it never makes the call. Could it be because I created two process objects or two runtime objects?

If you need anymore info, please ask. I modified the code a little to take out some stuff that shouldn't be publicized 🙂
 
Processes created by Runtime.exec likely exist outside the Java machine. It's likely platform VM implementation-dependant what needs to be done to execute/cleanup those processes. If you expect those scripts to be run sequentially, I would look at including a Process.waitFor() on the result of the first exec() call.
 
Originally posted by: FeathersMcGraw
Processes created by Runtime.exec likely exist outside the Java machine. It's likely platform VM implementation-dependant what needs to be done to execute/cleanup those processes. If you expect those scripts to be run sequentially, I would look at including a Process.waitFor() on the result of the first exec() call.

So just add a process.waitFor(); after the first process = runtime.exec(blah blah)

and catch the InterruptedException?
 
Originally posted by: FeathersMcGraw
Originally posted by: dabuddha

So just add a process.waitFor(); after the first process = runtime.exec(blah blah)

and catch the InterruptedException?

It's just a guess, but it's all I got.

Ok Ill try that real quick. Thanks btw for the idea 🙂
 
Originally posted by: FeathersMcGraw
Originally posted by: dabuddha

So just add a process.waitFor(); after the first process = runtime.exec(blah blah)

and catch the InterruptedException?

It's just a guess, but it's all I got.

It worked! ( sorta) I added the waitfor after the 2nd process. I guess what it was doing was it'd execute the command but after exiting the method, the process object would lose scrope and would be destroyed. The 2nd script actually takes some time to complete because it's ftping some large files over.
thanks!
 
Back
Top