title: Redirect output from one python script to another argparse
body: <p>This is probably a silly question but I've been struggling with this for a while now and I could not make it work. Basically what I am trying to do is use a script output with the command line passed arguments as an input for another script with arguments as well. This is my approach so far, I kind of feel that I am missing something though.</p>
  
  <p>Let's suppose the following <code>script1.py</code></p>
  
  <pre><code># !/usr/bin/env python3
  
  import argparse
  import sys
  
  def create_arg_parser():
      parser = argparse.ArgumentParser()
      parser.add_argument("-n", "--number", type=int, help="numbers range")
      return parser.parse_args()
  
  def main_a():
      nrange = parsed_args.number
      l = [i for i in range(nrange)]
      return l
  
  
  if __name__ == "__main__":
      parsed_args = create_arg_parser()
      print(main_a())
  </code></pre>
  
  <p>and <code>script2.py</code> </p>
  
  <pre><code># !/usr/bin/env python3
  
  import os
  import subprocess
  import argparse
  
  def create_arg_parser():
      parser = argparse.ArgumentParser()
      parser.add_argument("-o", "--outdir", type=str, help="outdir path")
      return parser.parse_args()
  
  def main_b():
  
   # the -n argument here should be inherited from script1.py and not manually set to 5
      process = subprocess.Popen(["python", "script1.py", "-n", "5"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  
      output = process.communicate() # let it run the list from script1.py
     with open(os.path.join(parsed_args.outdir, "list.txt"), "w") as f:
          f.write(output[0].decode('utf-8'))
  
  if __name__ == "__main__":
  
      parsed_args = create_arg_parser()
      main_b()
  </code></pre>
  
  <p>This actually works (kinda actually), apart from the fact that I am getting the list outputted from <code>script1.py</code> written alongside the <code>-n</code> argument. What I am trying to do here is use the list created from script1.py as input in script2.py, but just passing the command line arguments once. So for instance, use or inherit the arguments used for <code>script1.py</code> in <code>script2.py</code>. I know this could be done putting all in the same script but this is just an example, I am trying to write a <code>*gml</code> graph in the real problem.</p>
  
  <p>Any idea what I am missing here? Or is there any workaround or a simpler alternative to my approach?</p>