So python has a convenient function as part of pwntools
where one can sendline()
to an executable. How can I emulate this functionality in bash?
Example
#whatever.py
x = input("First input please: ")
y = input("Second input please: ")
I know I can echo "input1" | python3 whatever.py
to answer the first input, but I can't make it work multiline (echo "input1\ninput2" | ...
doesn't work, and neither does echo "input1"; echo "input2" | ...
).
echo -e
to interpret the\n
as a newline. Or better useprintf '%s\n' input1 input2
- see Why is printf better than echo?( echo "input1" ; echo "input2" ) | ...
or{ echo "input1" ; echo "input2" } | ...
(with the parentheses/braces) work for your use case?{ }
you need;
or newline after second (echo) command; with( )
you don't