title: I have integrated a bash command into my Python code - how can I get this command to take an input from the shell?
body: <p>I have added a bash command to my Python script - this bash command is used to linearise an input file (i.e. take a file with many lines, and merge it into one line). It works when I manually write the name of the file for the command (in this example, the input file is called input.txt):</p>
  
  <pre><code>import subprocess
  
  holder = subprocess.Popen('perl -ne "chomp;print;" input.txt', shell=True, stdout=subprocess.PIPE).stdout.read()
  
  print(holder)
  </code></pre>
  
  <p>However, I would like this bash command to take the name of the file specified by the user in the command line, and linearise it. </p>
  
  <p>I have already tried to achieve this using <code>%s</code>:</p>
  
  <pre><code>import subprocess
  import sys
  import os
  
  path = sys.argv[1]
  file = open(path, 'r')
  inp = file.read()
  
  holder = subprocess.Popen('perl -ne "chomp;print;" %s' % inp, shell=True, stdout=subprocess.PIPE).stdout.read()
  
  print(holder)
  </code></pre>
  
  <p>However, when I try this, the shell freezes and shows no output, and the bash <code>$</code> prompt does not show, there is no error message. </p>
  
  <p>I would like to know if there is a valid way to add a user input in this case and would appreciate any help.</p>
  
  <p>EDIT: just to clarify, here is what I type into my shell to run the program with the second example:</p>
  
  <p><code>$ python3 program.py input.txt</code></p>