When I try calling the below code, I run into the following error: "You must specify a format when providing data via STDIN (pipe)."
subprocess.call(["in2csv", "--format", "xls", a_file, ">", output_file], shell=True)
I'm not sure why this is the case because I am telling it what the initial format is. I've looked at the docs, which isn't clear about the distinction between --format and -f.
Update: I've changed it to use argparse to simplify passing the arguments following this recommendation. I'm also using Popen as used here, which is apparently safer than using shell=true flag according to the docs.
parser = argparse.ArgumentParser()
parser.add_argument('in2csv')
parser.add_argument('--format')
parser.add_argument('xls')
parser.add_argument(a_file)
parser.add_argument(">")
parser.add_argument(output_file)
args = parser.parse_args()
print args
subprocess.Popen(args)
cmd =["in2csv", "--format", "xls", "file.xls", ">", "file.csv"]. Thensubprocess.call( ' '.join(cmd), shell=True)should work. I am not sure whysubprocess.call( 'cmd, shell=True)will not work. I ranin2csv -andin2csv --from directly the command line and received the same error:in2csv: error: You must specify a format when providing data via STDIN (pipe).subprocess.Popencan be used to pipe the output to a file using subprocess.PIPE as in eg.subprocess.Popen([cmd],stdout=fd,stderr=subprocess.PIPE,shell=False)and personally I dont think you need args parse as long as you are not passing parameters to the command line all you need is the correct string likecmd = "in2csv --format xls {0}.format(a_file)"Also please check the return from subprocess.Popen and make the call blocking to complete the command before exit