zoukankan      html  css  js  c++  java
  • oc 执行shell 脚本

     

    -(id) InvokingShellScriptAtPath :(NSString*) shellScriptPath

    {

        NSTask *shellTask = [[NSTask alloc]init];

        [shellTask setLaunchPath:@"/bin/sh"];

        NSString *shellStr = [NSString stringWithFormat:@"sh %@ 参数1",shellScriptPath];

       

     

    //    -c 表示将后面的内容当成shellcode来执行

     

        [shellTask setArguments:[NSArray arrayWithObjects:@"-c",shellStr, nil]];

            

        NSPipe *pipe = [[NSPipe alloc]init];

        [shellTask setStandardOutput:pipe];

            

        [shellTask launch];

            

        NSFileHandle *file = [pipe fileHandleForReading];

        NSData *data =[file readDataToEndOfFile];

        NSString *strReturnFromShell = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];

        NSLog(@"The return content from shell script is: %@",strReturnFromShell);

            

        return strReturnFromShell;

     

     

    }

  • 相关阅读:
    驱动Makefile
    ioremap
    file结构体
    Python基础-语法知识
    企业运营对 DevOps 的「傲慢与偏见」
    漂亮得不像实力派!
    如何用 OneAPM 优化你的 Node.js 应用?
    全球说:要给 OneAlert 点100个赞
    DevOps 和技术债务偿还自动化
    PHP 性能分析与实验(二)——PHP 性能的微观分析
  • 原文地址:https://www.cnblogs.com/Xujg/p/10915666.html
Copyright © 2011-2022 走看看