
import os
import subprocess

if __name__ == '__main__':
    if os.environ.has_key('APP'):
        graphical_app = os.environ['APP']
        process = subprocess.Popen(graphical_app, shell=True,
                                   stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        stdoutdata, stderrordata = process.communicate()
        print(stdoutdata)
        subprocess.call(['sudo', 'supervisorctl', 'shutdown'],
                        stdout=subprocess.PIPE)


import os
import subprocess

if __name__ == '__main__':
    if os.environ.has_key('APP'):
        graphical_app = os.environ['APP']
        if os.environ.has_key('ARGS'):
            extra_args = os.environ['ARGS']
            command = graphical_app + ' ' + extra_args
        else:
            command = graphical_app

        process = subprocess.Popen(command, shell=True,
                                   stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        stdoutdata, stderrordata = process.communicate()
        print(stdoutdata)
        subprocess.call(['sudo', 'supervisorctl', 'shutdown'],
                        stdout=subprocess.PIPE)

Support an ARGS enviromental variable for extra command arguments.
Support an ARGS enviromental variable for extra command arguments.

  
  import os
  import subprocess
  
  if __name__ == '__main__':
      if os.environ.has_key('APP'):
          graphical_app = os.environ['APP']
+         if os.environ.has_key('ARGS'):
+             extra_args = os.environ['ARGS']
+             command = graphical_app + ' ' + extra_args
+         else:
+             command = graphical_app
+ 
-         process = subprocess.Popen(graphical_app, shell=True,
+         process = subprocess.Popen(command, shell=True,
                                     stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
          stdoutdata, stderrordata = process.communicate()
          print(stdoutdata)
          subprocess.call(['sudo', 'supervisorctl', 'shutdown'],
                          stdout=subprocess.PIPE)
  
Support an ARGS enviromental variable for extra command arguments.
## Code Before:

import os
import subprocess

if __name__ == '__main__':
    if os.environ.has_key('APP'):
        graphical_app = os.environ['APP']
        process = subprocess.Popen(graphical_app, shell=True,
                                   stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        stdoutdata, stderrordata = process.communicate()
        print(stdoutdata)
        subprocess.call(['sudo', 'supervisorctl', 'shutdown'],
                        stdout=subprocess.PIPE)

## Instruction:
Support an ARGS enviromental variable for extra command arguments.
## Code After:

import os
import subprocess

if __name__ == '__main__':
    if os.environ.has_key('APP'):
        graphical_app = os.environ['APP']
        if os.environ.has_key('ARGS'):
            extra_args = os.environ['ARGS']
            command = graphical_app + ' ' + extra_args
        else:
            command = graphical_app

        process = subprocess.Popen(command, shell=True,
                                   stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
        stdoutdata, stderrordata = process.communicate()
        print(stdoutdata)
        subprocess.call(['sudo', 'supervisorctl', 'shutdown'],
                        stdout=subprocess.PIPE)
