I have a problem with python tools to call a sub process or any process at all. My ELF is sitting on my PC at the same folder as the python code does. The ELF works something like: input,output,input,output: like 40 times, and I need to send data to the input of the program. At first I tried with pipe: python -c 'print "0 0xdeadbeef hello 5"*40'| ./elf
but the elf has gone crazy and made my PC stop working. If you didn't understand what I meant so try to understand now: The elf waits for input from 3 options[0/1/2], I chose 0 and than the elf asks me for string,another string and an int. After that the elf returns to the options menu again, and I need to do it for 40 times, and then I need to send 2 for the elf so actually, I need to something like: python -c 'print "0 0xdeadbeef hello 5"*40 +"2"'| ./elf
but the first command does not work so it can't work as well. After trying the 'shelling solution' I tried to use subprocess library to run the elf from my code, but it didn't work as well, I tried both communicate function and write to the stdout but it has been killed and it even does not show any printing of the elf and I even can't know if what I'm sending is going to the input. Also, I tried call function because none has worked for me.
code:
import subprocess
p=subprocess.Popen(['./elf'],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
out = p.communicate(input='0') #not responding
Also tried p.stdin.write('0\n')
and then read from that stdout but still no answer
Thanks you all!
python -c 'print "0 0xdeadbeef hello 5"*40
It's not clear what exact output you expect this to produce. I think you expect something like
0 0xdeadbeef hello 5
0 0xdeadbeef hello 5
...
But what this actually produces is:
0 0xdeadbeef hello 50 0xdeadbeef hello 50 0xdeadbeef hello 50 0xdeadbeef ...
which is probably not something your ./elf
expects or correctly handles.
If you really want the former and not the latter, try:
python -c 'print "0 0xdeadbeef hello 5\n"*40 +"2"'| ./elf
User contributions licensed under CC BY-SA 3.0