Reputation: 153
Basically, i'm trying to run multiprocessing using Python that will utilize telnet to a server in order to send HTTP request. The request is recorded in request.txt full request with header.
In my python code, I've tested the full multiprocessing, it works like magic. However, once placed in the server, the bash commands are not executed properly.
What I'm trying to replicate in Python is the below bash sample:
START=
(
cat request.txt
sleep 2
)| telnet 0 999
what I'm doing in my python source code is:
os.system("START=\
(\
cat request.txt \
sleep 2 \
)| telnet 0 999\
")
what I'm getting is:
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
Connection closed by foreign host.
When I run the request manually over bash terminal, it runs perfectly without an error. However, when trying to execute python application, it gives the above behavior.
P/S the reason why I'm not posting the full source code is because my issue is only related to os.system - the bash part of the application.
Thank you
Upvotes: 0
Views: 65
Reputation: 1558
I do not know if this is the answer to your problem. But looking at your code, your multiline string evaluates to START=( cat request.txt sleep 2 )| telnet 0 999
. So cat request.txt sleep 2
comes as one command. This might be the cause to the problem. You can add a ;
after cat request.txt
and try.
By the way it is recommended to use triple quotes for multiline strings in python instead of escaping each line with \
Adding the worked solution:
os.system('''START=
(
cat vsip.txt;
sleep 2
)| telnet 0 999
''')
Upvotes: 2