//命令原型:sh -c "echo 密码 | su -c 'ls --help' "
                //转载请注明:http://www.cnblogs.com/bandy/p/7069503.html
                NSTask *task = [NSTask new];
                [task setLaunchPath:@"/bin/sh"];
                [task setArguments:[NSArray arrayWithObjects:@"-c", @"/bin/echo alpine | /bin/su -c '/bin/ls --help' ", nil]];
                NSPipe *pipe = [NSPipe pipe];
                [task setStandardOutput:pipe];
                [task launch];
                NSData *data = [[pipe fileHandleForReading] readDataToEndOfFile];
                [task waitUntilExit];
                NSString * string;
                string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];//root
                NSLog(@"Result: %@", string);
                //转载请注明:http://www.cnblogs.com/bandy/p/7069503.html

 

相关文章:

  • 2022-02-10
  • 2021-08-19
  • 2022-01-19
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2021-09-29
  • 2022-12-23
猜你喜欢
  • 2021-07-29
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
相关资源
相似解决方案