Skip to content
Advertisement

How can I use a child process to run a .class file from a parent directory?

In this case, I am using Node.js ChildProcess. Let’s say the application file (index.js, for example) is in folder1. This folder also has folder2, which is where the class file is. So, when I call spawn from folder1, the command’s current directory is folder1. However, I can’t do java ./folder2/MyFile.

Here’s what I tried:

JavaScript

Using function run on ./folder2/MyFile returns:

JavaScript

I assume this has something to do with java and classpath. I saw an answer involving setting the classpath to the target directory (folder2) but it didn’t do anything.

In short, how can I run a .class file from a different directory?

Advertisement

Answer

You can use exec instead of spawn so you can use two commands with & symbol which the second command runs when the first one finish without fail. I think this might work for you.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement