Python Forum
Using subprocess to execute complex command with many arguments
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using subprocess to execute complex command with many arguments
#1
I have a shell script that is as follows:

LOAD_RRD=sysmon.rrd
DISK_RRD=disk.rrd
DISKTEMP_RRD=disktemp.rrd

rrdtool graph load1h.png \
		-Y -u 1.1 -l 0 -L 5 -v "Load" -w 700 -h 200 -t "Load stats - `/bin/date`" \
        --start end-"1h" --x-grid MINUTE:1:MINUTE:5:MINUTE:10:0:%R \
		-c ARROW\#000000 \
		DEF:load1=$LOAD_RRD:load1:AVERAGE \
		DEF:load5=$LOAD_RRD:load5:AVERAGE \
		DEF:load15=$LOAD_RRD:load15:AVERAGE \
		LINE1:load1\#ff0000:"Load average 1 min" \
		LINE1:load5\#ff6600:"Load average 5 min" \
		LINE2:load15\#ffaa00:"Load average 15 min" \
		COMMENT:"	\j" \
		COMMENT:"\j" \
		COMMENT:"	" \
		GPRINT:load15:MIN:"Load 15 min minimum\: %lf" \
		GPRINT:load15:MAX:"Load 15 min maximum\: %lf" \
		GPRINT:load15:AVERAGE:"Load 15 min average\: %lf" \
		COMMENT:"	\j" \
		COMMENT:"	" \
		COMMENT:"	\j" >/dev/null;
I want to convert it to python using the subprocess module and run similar commands but with manipulating the internal variables and parameters.

I was thinking of copying the whole command in a single python string cmd_str then run
subprocess.run(cmd_str, shell=True)
But I'm not on the best way to escape all those internal quotes and other special symbols.
Any suggestions?
Reply


Messages In This Thread
Using subprocess to execute complex command with many arguments - by medatib531 - Apr-26-2023, 01:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to pass a mongdb command to a module and execute it. cspower 0 341 Feb-03-2024, 09:54 PM
Last Post: cspower
  use subprocess on linux\pi wwith a "grep " command korenron 2 8,186 Oct-19-2021, 10:52 AM
Last Post: DeaD_EyE
  Error when running mktorrent subprocess command pythonnewbie138 4 3,912 Sep-16-2020, 01:55 AM
Last Post: pythonnewbie138
  Select correct item from list for subprocess command pythonnewbie138 6 3,359 Jul-24-2020, 09:09 PM
Last Post: pythonnewbie138
  Subprocess command working for one cmd and for cmd one not wrking PythonBeginner_2020 0 4,161 Mar-25-2020, 01:52 PM
Last Post: PythonBeginner_2020
  execute linux command with arguments sivareddy 2 2,282 Feb-10-2020, 03:23 PM
Last Post: sivareddy
  How to parallel executing a command using subprocess? larkypython 0 2,175 Nov-28-2019, 03:49 PM
Last Post: larkypython
  changing the process command line arguments in python Skaperen 3 3,048 Aug-19-2019, 02:40 PM
Last Post: wavic
  A question about subprocess taking input from command line and returning output! Aurimas 8 5,264 May-15-2019, 04:02 PM
Last Post: Aurimas
  Issue with command line arguments artblinked 2 3,144 Feb-22-2019, 03:04 PM
Last Post: artblinked

Forum Jump:

User Panel Messages

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