0

ココアアプリで次を実行しようとしています:

猫のPATHTOFILE | python -mjson.tool > OUTPUTFILE

    NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath: @"/bin/cat"];

    NSArray *arguments = [NSArray arrayWithObject: path];
    [task setArguments: arguments];

    NSPipe *pipe = [NSPipe pipe];
    [task setStandardOutput:pipe];
    [task launch];

    NSTask *task2 = [[NSTask alloc] init];
    [task2 setLaunchPath:@"/usr/bin/python"];
    NSArray *arguments2 = [NSArray arrayWithObject:[NSString stringWithFormat:@"-mjson.tool > %@.beautify", path]];
    [task2 setArguments:arguments2];
    [task2 setStandardInput:pipe];

    NSPipe *pipe2 = [NSPipe pipe];
    [task2 setStandardOutput:pipe2];
    [task2 launch];

ただし、次のエラーが表示されます: /usr/bin/python: ファイル名によるインポートはサポートされていません。

何か案は?

4

1 に答える 1

0

Pythonエラーのようです。

/usr/bin/python -mjson.tool次のファイルを呼び出します: (端末から使用する場合)

/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/tool.py

その内容は

""" headers..."""
import sys
import json

def main():
    if len(sys.argv) == 1:
        infile = sys.stdin
        outfile = sys.stdout
    elif len(sys.argv) == 2:
        infile = open(sys.argv[1], 'rb')
        outfile = sys.stdout
    elif len(sys.argv) == 3:
        infile = open(sys.argv[1], 'rb')
        outfile = open(sys.argv[2], 'wb')
    else:
        raise SystemExit(sys.argv[0] + " [infile [outfile]]")
    try:
        obj = json.load(infile)
    except ValueError, e:
        raise SystemExit(e)
    json.dump(obj, outfile, sort_keys=True, indent=4)
    outfile.write('\n')


if __name__ == '__main__':
    main()

これらの import ステートメントを解決できません。確かに、ターミナルほど多くのことを認識しておらず、これを見つけることができないためです... NSTaskが正しいパスでPythonを起動していないことを確認してください

于 2013-02-06T08:21:43.740 に答える