我使用下面的代码来获取命令“ps -ef | grep java”
的输出import subprocess pp1=subprocess.Popen(["ps" , "-ef"],stdout=subprocess.PIPE) pp2=subprocess.Popen(['grep','java.util'],stdin=pp1.stdout,stdout=subprocess.PIPE) out,err=pp2.communicate() print out
但它只给出第一行结果,而不是完整的命令行。
Current Output: root 17363 1 16 03:13 ? 01:53:26 /opt/java/jdk7/bin/java -Djava.util.logging.config.file=/opt/tomcat/tomcat7//conf/logging.properties -server -Xms6144m -\n Expected Output: root 17363 1 16 03:13 ? 01:55:40 /opt/java/jdk7/bin/java -Djava.util.logging.config.file=/opt/tomcat/tomcat7//conf/logging.properties -server -Xms6144m -Xmx6144m -Dsun.rmi.dgc.client.gcInterval=2000000000 -Dsun.rmi.dgc.server.gcInterval=2000000000 -Dsun.reflect.inflationThreshold=15 -Dsun.reflect.noInflation=true -Dsun.security.ssl.allowUnsafeRenegotiation=true -XX:MaxPermSize=1024m -XX:+PrintClassHistogram -XX:+PrintHeapAtGC -verbose:gc -Xloggc:/opt/apache-tomcat-7.0.23/logs/gclog-20151006T0313 -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -XX:+PrintAdaptiveSizePolicy -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime -Dcom.sun.management.jmxremote.port=9003 -Dcom.sun.management.jmxremote.password.file=/opt/apache-tomcat-7.0.23/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/opt/apache-tomcat-7.0.23/conf/jmxremote.access -Dcom.sun.management.jmxremote.ssl=false -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/opt/tomcat/tomcat7//endorsed -classpath /opt/tomcat/tomcat7//bin/bootstrap.jar:/opt/tomcat/tomcat7//bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat/tomcat7/ -Dcatalina.home=/opt/tomcat/tomcat7/ -Djava.io.tmpdir=/opt/tomcat/tomcat7//temp org.apache.catalina.startup.Bootstrap start
有人可以告诉我如何获得完整的命令行。