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;

     

     

    }

  • 相关阅读:
    Spring AOP 实现原理
    Spring Aop实现方式总结
    Spring Aop重要概念介绍及应用实例结合分析
    Spring Aop
    常见的排序算法
    MINA2.0原理
    Java和Tomcat类加载机制
    Java 8 新特性概述
    Java类加载机制深度分析
    jetty之建立多Connector
  • 原文地址:https://www.cnblogs.com/Xujg/p/10915666.html
Copyright © 2011-2022 走看看