title: Using subprocess or alike to redirect the Standard Output of a shell command to a dynamic directory/filename
body: <p>I have been coding for a few months and hit a wall.
  The following code simply prints a menu and runs a few shell commands and outputs these to the screen.
  What i'd like to do is send the output of the menu 1 options to a "workspace".
  I'm calling a workspace a user inputted directory whereby when a shell command is executed it saves the the std in as a file to that respective directory.
  I will have over 50 different command that will be executed eventually and i want them to all be neatly stored in the relative directories.
  Currently using Python 3.4</p>
  
  <p>So far my code can, request user input for a workspace, which inturn creates a relative directory.
  What I need to is get a file to be outputted.</p>
  
  <pre><code>#Imports
  import os
  import subprocess
  
  
  #Set Globals for Workspace to 0
  workspace = 0
  absolute_path = 0
  
  
  #Initally clear the screen
  os.system('clear')
  
  #Define Option 0 - Create a Workspace
  def workspace_menu():
      print ("Enter the name of the Workspace or type 'q' or 'quit' to return to the main menu")
      print ("")
      workspace_input = input(":")
      if workspace_input in ("q", "quit"):
          os.system('clear')
      else:
  #Define the current working directoy (__file__)
      script_dir = os.path.dirname(__file__)
      relative_path = 'workspaces/'
      joined_path = os.path.join(script_dir, relative_path)
      os.chdir(joined_path)
      if os.path.exists(workspace_input):
          print ("Directory already Exists! - Try a different name")
          input("Press any key to Return to the Main Menu")
          os.system('clear')
      else:
          make_path = os.makedirs(workspace_input)
          absolute_path = joined_path + workspace_input
          global absolute_path
          absolute_path = absolute_path
          global workspace
          workspace = 1
          print ("Workspace created!"), absolute_path
          input("Press any Key to Continue")
          os.system('clear')
          return
  
  #Define the Main Menu
  def menu():
      print(" 0) Add a Workspace")
      print(" 1) System Tasks")
      print("11) Exit")
  
  
  #Define System Tasks
  def system_tasks():
      os.system('clear')
      print(" 1) Display Local Network information")
      print(" 5) Back")
      system_tasks_answer = int(input(":"))
      if system_tasks_answer == 1:
          print("The Local Network Configuration of this OS are:")
          print("")
          ifconfig = subprocess.call(['/sbin/ifconfig'])
          dns = subprocess.call(['cat', '/etc/resolv.conf'])
          print("")
          print(workspace)
          lni_menu = input("Press any Key to Continue")
          system_tasks()
          os.system('clear')
      elif system_tasks_answer == 5:
          os.system('clear')
  
  
  loop=True
  
  while loop:
      print (menu())
      mm_answer = int(input(":"))
      if mm_answer ==0:
          workspace_menu()
      elif mm_answer ==1:
          system_tasks()
      elif mm_answer ==11:
          break
      else:
          input("You did not give a valid answer, press any key to try again") 
          os.system('clear')
  </code></pre>