scala VS python2 操作shell对比例子
Scala:
/** * Created by sunxu on 2015/9/30. */ import scala.sys.process._ import java.io.File //在相应目录执行shell命令,返回值赋值给变量 val exitValue = Process("hadoop jar pathread-analytics-0.0.1.jar com.duxiu.pathread.stcs.StcsByFieldJob /pathread/2015/10-08 /user/sunxu/test ssid 13671489", new File("/opt/users/sunxu/")).! println("--------------------------------------------------------") if (exitValue == 0) { val listInfo = "sh /opt/users/sunxu/test.sh" !! println(listInfo) }
Python:
__author__ = 'sunxu' import subprocess cmd = "hadoop jar pathread-analytics-0.0.1.jar com.duxiu.pathread.stcs.StcsByFieldJob /pathread/2015/09-29 /user/sunxu/test ssid 13210904" hadoopCmd = subprocess.Popen(cmd.split(" "), stdout=subprocess.PIPE) #print hadoopCmd.communicate() 运行这句下边的调用会报错,file stream is closed print '-------------------------------------' msgInfo = subprocess.Popen(["grep","ssid"], stdin=hadoopCmd.stdout,stdout=subprocess.PIPE) output = msgInfo.communicate() print output