Python Forum

Full Version: Code that works on py2 and not in py3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone
this is Pedro and this is my first post. I am trying to write a script to make graphs with xmgrace (graphics program) under linux. There are serveral modules available on the net but none of them work with python 3.
In general terms what I want to do is to launch a process that receives input through a descriptor, in my case the command is 'xmgrace -dpipe <descriptor>'. I wrote the code below that works fine in python 2 but does nothing in python 3.

Any ideas of what's wrong?
Thank you in advance


import os

cmd=('xmgrace','-noask','-dpipe',)

fr,fw=os.pipe()

cmd=cmd+(repr(fr),)

pid=os.fork()

if pid==0:
	for i in range(64):
		if i not in (fr,0,1,2):
			try:
				os.close(i)
			except OSError:
				pass
	os.execvp('xmgrace',cmd)
else:
	os.close(fr)
	pipe=os.fdopen(fw,'w',1)
	
	pipe.write('title "test"\n')
	pipe.flush()
You could perhaps try os.set_inheritable(fr, True) before the fork.
(Nov-29-2019, 11:39 AM)Gribouillis Wrote: [ -> ]You could perhaps try os.set_inheritable(fr, True) before the fork.

Thanks a lot, it works now with py2!!

(Nov-29-2019, 11:12 AM)Larz60+ Wrote: [ -> ]see: https://docs.python.org/3.8/library/2to3.html

Thanks a lot