fork download
  1. import subprocess
  2.  
  3. p = subprocess.run(
  4. r'''echo -e 'FROM busybox\nRUN echo "hello world, from echo -e"' | nl''',
  5. shell=True, check=True)
  6.  
  7. q = subprocess.run(
  8. r'''printf '%s\n' 'FROM busybox' 'RUN echo "hello world, from printf"' | nl''',
  9. shell=True, check=True)
  10.  
  11. r = subprocess.run(['nl'],
  12. input='FROM busybox\nRUN echo "hello world, from Python with input="' ,
  13. text=True, check=True)
  14.  
Success #stdin #stdout 0.03s 10120KB
stdin
Standard input is empty
stdout
     1	-e FROM busybox
     2	RUN echo "hello world, from echo -e"
     1	FROM busybox
     2	RUN echo "hello world, from printf"
     1	FROM busybox
     2	RUN echo "hello world, from Python with input="