I have a jython script server (called rajant_server.py) that interacts with the java api file to communicate through special network radio stations. I have a python program that acts as a client (and also does a few other things). Currently, I have to start the server first by opening a command / terminal window and typing:
cd [path to directory containing rajant_server.py jython rajant_server.py
As soon as the server successfully connects, it waits for the client that I start:
cd [path to directory containing python client program] python main.py
When a client connects, the server prints information (currently for debugging) in this command / terminal window, and the client program displays debugging information in this command / terminal window. What I want to do is get rid of the complicated process by calling jython from my main.py program using the subprocess module.
The task consists of two times:
1 - I need the rajant_server.py program to open my own terminal / command window in it
2 - jython should run in the directory where the rajant_server.py file is stored, in other words, entering the command line / Terminal Window does not work (do not ask me why):
jython C:/code_dir/comm/server/rajant_server.py
a
cd C:/code_dir/comm/server jython rajant_server.py
works.
Alright ... I have something to work on. It seems like a hack, so I will still love ideas for a better approach. Here is what I am doing now:
serverfile = r'rajant_server_v2.py' serverpath = os.path.join(os.path.realpath('.'),'Comm',serverfile) serverpath = os.path.normpath(serverpath) [path,file] = os.path.split(serverpath) command = '/C jython '+file+'\n' savedir = os.getcwd() os.chdir(path) rajantserver = subprocess.Popen(["cmd",command],\ creationflags = subprocess.CREATE_NEW_CONSOLE)
If you have a solution that will work on both Linux and Windows, you will become my hero. For some reason, I could not change the stdin or stdout specifications in the subprocess when I added createflags = subprocess.CREATE_NEW_CONSOLE.