def getpcmd(pid):
 if (os.name == 'nt'):
  cmd = ('wmic path win32_process where ProcessID=%s get Commandline' % (pid,))
  with os.popen(cmd, 'r') as p:
   lines = [line for line in p.readlines() if (line.strip('\r\n ') != '')]
   if lines:
    (_, val) = lines
    return val
 else:
  try:
   with open('/proc/{0}/cmdline'.format(pid), 'r') as fh:
    return fh.read().replace('\x00', ' ').rstrip()
  except IOError:
   pass
 return '[PROCESS_WITH_PID={}]'.format(pid)

def getpcmd ( pid ) : if ( os . name == 'nt' ) : cmd = ( 'wmic path win32_process where ProcessID=%s get Commandline' % ( pid , ) ) with os . popen ( cmd , 'r' ) as p : lines = [ line for line in p . readlines ( ) if ( line . strip ( '\r\n ' ) != '' ) ] if lines : ( _ , val ) = lines return val else : try : with open ( '/proc/{0}/cmdline' . format ( pid ) , 'r' ) as fh : return fh . read ( ) . replace ( '\x00' , ' ' ) . rstrip ( ) except IOError : pass return '[PROCESS_WITH_PID={}]' . format ( pid )
returns command of process .