// Execute the external C program "program.exe" using the values entered on the screen as parameters void executeExternalProgram() { // Get the absolute path of the C program file to execute string programPath = getFilePath("program.exe"); // Prepare an array to store the command used to launch the C program string commandWords[4]; // Put the absolute path of the program to run in the first element commandWords[0] = programPath; // The remaining elements are parameter values passed to the program, so get them from the screen commandWords[1] = getComponentText(aField); // Input value A commandWords[2] = getComponentText(bField); // Input value B commandWords[3] = getComponentText(cField); // Input value C // Prepare the program in an executable state (passing the command prepared above here) int processID = newProcess(commandWords); // Specify character encodings to prevent Japanese text from becoming garbled // (If that causes garbling instead, try specifying "UTF-8", etc.) setProcessInputEncoding(processID, "CP932"); setProcessOutputEncoding(processID, "CP932"); setProcessErrorEncoding(processID, "CP932"); // Run the program and wait for it to finish startProcess(processID); waitForProcess(processID); // Get the program output and display it on the screen string outputContent = getProcessOutput(processID); setComponentText(outputArea, outputContent); // Get the program error output and display it on the screen string errorContent = getProcessError(processID); setComponentText(errorArea, errorContent); }