0

I am here with a issue that : I have a GUI (wxpython), it has spinctrl, the output of spinctrl must be sent to c file, which accept command line argument, so whenever i execute c file using subprocess as it accepts value from GUI the spinctrl value must be sent to it instead of manual typing.

My code is:

      ps = "password" 
      var1 = self.sc1.Getvalue()
      var2 = self.sc2.Getvalue()
      subprocess.call(['echo xsxsxs | sudo "./license.exe"', str(ps), str(var1), str(var2)],shell = True)

whenever i run this script it doesnot show output/error :(

if i remove echo xsxsxs| sudo from the line 4 and then execute then it show error: "you must be root user","Invalid password", "segmentation fault".

1 Answer 1

2

Whenever you use shell=True to subprocess.Popen (or one of the convenience wrappers), you should pass a string exactly the way you would type it in your shell, not a list.

from the docs:

If shell is True, it is recommended to pass args as a string rather than as a sequence.

Sign up to request clarification or add additional context in comments.

2 Comments

I didnot understand your concept. can you please clarify it?
Since your last argument is shell=True, you should build the string for the entire command yourself: cmd = 'echo xsxsxs | sudo "./license.exe" {} {} {}'.format(ps, var1, var2) then subprocess.call(cmd, shell=True)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.