-2

次のコードでJavaで使用したように、目的のcで端末コマンドを実行するために使用される関数を見つけるのを手伝ってください。obj c または cocoa で端末プロセスを実行するためにどの関数が使用されているかだけを知りたいです。

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);
        }
4

1 に答える 1

0

NSTask を使用できます。Java バージョンを標準出力 (未読のまま) に出力する必要がある例 (未テスト):

- (IBAction)speak:(id)sender
{
    NSTask *task = [[NSTask alloc] init];
    task.launchPath = @"java";
    task.arguments  = @[@"-v"];
    [task launch];
    [task waitUntilExit];
    //use task.standardOutput to read
}
于 2013-10-29T18:27:46.123 に答える