tags:

views:

732

answers:

2
        myfile = open("wrsu"+str(i)+'_'+str(j)+'_'+str(TimesToExec)+".txt",'w')
        sys.stdout = myfile
        p1 = subprocess.Popen([pathname,"r", "s","u",str(i),str(j),str(runTime)],stdout=subprocess.PIPE)
        output = p1.communicate()[0]
        print output,

When I use this to redirect the output of a exe to my own file, it always

a carriage return after each line, How to suppress it?

+2  A: 

Here's how I removed the carriage return:

 p = Popen([vmrun_cmd, list_arg], stdout=PIPE).communicate()[0]
 for line in p.splitlines():
 if line.strip():
     print line
Rob Carr
+1  A: 
def Popenstrip(self):
  p = Popen([vmrun_cmd, list_arg], stdout=PIPE).communicate()[0]
  return (line for line in p.splitlines() if line.strip())
odwl