How to execute 'ssconvert' command using subprocess

872 views Asked by At

I want to execute the following command:

ssconvert /data/sam.xls,/data/test.csv

I have tried:

 p = subprocess.Popen(["ssconvert", '/data/sam.xls','/data/test.csv'], stdout=subprocess.PIPE,shell=True)
   out = p.communicate()
   print"output", out

but it's not working.

How can I solve this issue?

2

There are 2 answers

0
Abdul Razak On BEST ANSWER

This is worked

import subprocess
subprocess.call(["ssconvert","sample.xlsx","sample.csv"],cwd="pathtoyourfile") # pathtoyourfile must contain the xlsx and csv files
0
jfs On

The correct command is not ssconvert /data/sam.xls,/data/test.csv. It should be: ssconvert /data/sam.xls /data/test.csv instead (note: the space, not comma between the input and output filenames).

If you use shell=True then you should pass the command as a string. There is no need to use shell=True in this case. If shell=False (default) then each command-line argument should be passed as a single list item:

#!/usr/bin/env python
import subprocess

subprocess.check_call(['ssconvert', '/data/sam.xls', '/data/test.csv'])

See Why subprocess.Popen doesn't work when args is sequence?