save = "/root/foo/"
PERF_PATH="/root/foobar/"
So, Initially I had the variable save and perf_path in the cmd. but now, I want to substitute it for enhanced readability.
I wanted to create a folder into which the variable app[a] will eventually get stored.
direc = os.mkdir(save + i + "-"+ j +"-" + k + "-" +l)
Creating a directory does not seem to a problem.
but joining a non-string value variable to a string seems to be a problem.
cmd = "taskset -c %s" + PERF_PATH + "perf2 stat -t %s e r4008387e1 -f -o" +save + direc + "%s.csv &" % (cpus_list[a],fpid[a],apps[a])
pro= subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE, preexec_fn=os.setsid)
TypeError: cannot concatenate 'str' and 'NoneType' objects
cmd = "taskset -c %s" + str(PERF_PATH) + "perf2 stat -t %s e r4008387e1 -f -o" +str(save) + str(direc) + "%s.csv &" % (cpus_list[a],fpid[a],apps[a])
that wasn’t of much help either.
any ideas how I can solve this?
os.mkdir()does not return anything, sodirecis set to None.Do this instead:
You really want to use
os.path.join()and string formatting to build paths though, it’ll be a lot easier to read:For
subprocess.Popen(), pass in a list instead of a string for the command and arguments, and leaveshellto the default value ofFalse, there is no need to have the shell handle that: