views:

44

answers:

2

hello all
Im attempting to start a server app (in erlang, opens ports and listens for http requests) via the command line using pexpect (or even directly using subprocess.Popen()).

the app starts fine, logs (via pexpect) to the screen fine, I can interact with it as well via command line...
the issue is that the servers wont listen for incoming requests. The app listens when I start it up manually, by typing commands in the command line. using subprocess/pexpect stops the app from listening somehow...
when I start it manually "netstat -tlp" displays the app as listening, when I start it via python (subprocess/pexpect) netstat does not register the app...

I have a feeling it has something to do with the environemnt, the way python forks things, etc. Any ideas?

thank you

basic example: note:
"-pz" - just ads ./ebin to the modules path for the erl VM, library search path
"-run" - runs moduleName, without any parameters.

command_str = "erl -pz ./ebin -run moduleName"  
child = pexpect.spawn(command_str)  
child.interact() # Give control of the child to the user

all of this stuff works correctly, which is strange. I have logging inside my code and all the log messages output as they should. the server wouldnt listen even if I started up its process via a bash script, so I dont think its the python code thats causing it (thats why I have a feeling that its something regarding the way the new OS process is started).

A: 

Can you show us some code so we can have a deeper look at it?

Fabian
certainly. I've included some code to the original post. if you have additional questions/need for details, I would be happy to fill in
deepblue
A: 

It could be to do with the way that command line arguments are passed to the subprocess.

Without more specific code, I can't say for sure, but I had this problem working on sshsplit ( https://launchpad.net/sshsplit )

To pass arguments correctly (in this example "ssh -ND 3000"), you should use something like this:

openargs = ["ssh", "-ND", "3000"]
print "Launching %s" %(" ".join(openargs))
p = subprocess.Popen(openargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

This will not only allow you to see exactly what command you are launching, but should correctly pass the values to the executable. Although I can't say for sure without seeing some code, this seems the most likely cause of failure (could it also be that the program requires a specific working directory, or configuration file?).

Martin Eve