-2

Please help me to find out which function is used to run a terminal command in objective c as i used in java in following code. I want to only know that which function is use in obj c or cocoa to execute a terminal process.

Runtime rt = Runtime.getRuntime();
        Process prcComile = rt.exec("javac -d F:/ F://" + fname.getText()+ ".java");
        InputStream iscmp = prcComile.getErrorStream();
        int cerrInt = iscmp.read();
        if (cerrInt == -1) {
            Process prc = rt.exec("java -cp  F:/ " +fname.getText());
            InputStream iserr = prc.getErrorStream();
            int errInt = iserr.read();
            if (errInt == -1) {
                InputStream is = prc.getInputStream();
                int readInt = is.read();

                String allOutput = "";
                while (readInt != -1) {
                    char ch = (char) readInt;
                    allOutput = allOutput + ch;
                    readInt = is.read();
                }

                txtOutput.setText(allOutput);
            } else {
                String errorString = "";
                while (errInt != -1) {
                    char ch = (char) errInt;
                    errorString += ch;
                    errInt = iserr.read();
                }
                txtOutput.setText(errorString);
            }
        } else {
            String errorString = "";
            while (cerrInt != -1) {
                char ch = (char) cerrInt;
                errorString += ch;
                cerrInt = iscmp.read();
            }
            txtOutput.setText(errorString);
        }
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130

1 Answers1

0

You can use NSTask. Example (untested) that should print the java version to standard output (which is left unread):

- (IBAction)speak:(id)sender
{
    NSTask *task = [[NSTask alloc] init];
    task.launchPath = @"java";
    task.arguments  = @[@"-v"];
    [task launch];
    [task waitUntilExit];
    //use task.standardOutput to read
}
Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101