Python Forum
script wanted: print the command
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
script wanted: print the command
#2
It's like reading the docs from subprocess...


#!/usr/bin/env python3

from subprocess import Popen, PIPE
import sys


args = sys.argv[1:]
print('Program:', args[0])
print('Arguments:', args[1:])


proc = Popen(args, shell=False, stdout=PIPE, stderr=PIPE)
stdout, stderr = proc.communicate()
exitcode = proc.wait()

print('Exitcode:', exitcode)
print('Stdout:', stdout.decode())
print('Stderr:', stderr.decode())

sys.exit(exitcode)
This example prints always: program, arguments, exitcode, stdout, stderr
This program does not work with tools like midnight commander or screen.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
script wanted: print the command - by Skaperen - Dec-08-2017, 04:53 AM
RE: script wanted: print the command - by DeaD_EyE - Dec-08-2017, 09:50 AM
RE: script wanted: print the command - by Skaperen - Dec-09-2017, 02:29 AM
RE: script wanted: print the command - by DeaD_EyE - Dec-10-2017, 11:21 AM
RE: script wanted: print the command - by Skaperen - Dec-11-2017, 02:20 AM
RE: script wanted: print the command - by wavic - Dec-12-2017, 12:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  a tree command using Shell Script that displays all the directories recursively apollo 1 2,075 Nov-18-2021, 10:04 PM
Last Post: BashBedlam
  script wanted: UNboxing database output Skaperen 0 1,806 Oct-27-2018, 03:04 AM
Last Post: Skaperen
  command line progam wanted: clock Skaperen 2 2,837 Apr-18-2018, 06:54 AM
Last Post: Gribouillis
  script wanted: clock for text mode screen Skaperen 2 3,132 Dec-26-2017, 01:57 AM
Last Post: Skaperen
  script wanted: ping and wait Skaperen 0 2,381 Dec-10-2017, 05:16 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020