I have an executable of c++ that opens a file and writes a line to it. Works fine by itself.
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ofstream fout;
fout.open("test.txt");
if(fout.is_open()){
cout<<"test"<<endl;
fout<<"Hello World!" << endl;
}
fout.close();
return 0;
}
And I made a main() in java to call it from there like so:
public static void main(String args[]){
File f = new Resources().getFile("test.exe");
System.out.println(f.exists());
String path = f.getAbsolutePath();
try{
Process p = new ProcessBuilder(path).start();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while(line != null){
line = br.readLine();
System.out.println(line);
}
p.destroy();
}catch(Exception e){
System.out.println(e.getMessage());
}
}
The first line in main is from my project, it finds the file, it works too.
The thing is when the exe is run alone it creates the file and writes to it. When I run the java main() the file is not created even though I get the output from the stdout. So the executable runs but doesn't create the file.
I am going nuts peaople... what do?