#include
#include
using namespace std;
int main() {
freopen( "input.txt", "r", stdin );
freopen( "output.txt", "w", stdout );
string s;
cin >> s;
cout << s;
return 0;
}
上記のC ++プログラムのa.exeファイルをJavaプログラムを使って実行するには?
私は次のを使用してみましたが、output.txtファイルが生成されていません。
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(..filepath.. )
ベストアンサー
import java.io.*;
public class Test {
public static void main(String[] args) {
Runtime run = Runtime.getRuntime();
try {
Process pp=run.exec("c:\a");
BufferedReader in =new BufferedReader(new InputStreamReader(pp.getErrorStream()));
// Do your Stuff
int exitVal = pp.waitFor();
System.out.println("Process exitValue: " + exitVal);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
}
}