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;

     

     

    }

  • 相关阅读:
    Git with SVN 协同设定
    Apache+Django+mod_wsgi安装目录
    ROR study
    PHP框架
    Gerrit 配置
    Garmin、任我游品牌自制等高线方法比较
    使用python发送outlook约会提醒邮件
    Apache部署多个django site project
    Aptana Studio 3安装(Windows)
    The Art of Readable Code
  • 原文地址:https://www.cnblogs.com/Xujg/p/10915666.html
Copyright © 2011-2022 走看看