Yi.He
Yi.He

Reputation: 69

How to handle ':' in command using os.popen

I am trying to call a program with:

os.popen("program -s:'*' -c:'A;B;C;'")

However, it seems that it was interpreted as shell command:

program -s '*' -c 'A;B;C;'

which result incorrect behavior.

Can somebody help me on how to hanle such situdations where ':' is inside shell commandline?

Upvotes: 0

Views: 64

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1124110

Don't use os.popen(), use the subprocess module instead:

import subprocess

result = subprocess.check_output(['program', "-s:'*'", "-c:'A;B;C;'"])

This returns the output of the program without running it through a shell, passing in the arguments directly without any additional parsing.

Upvotes: 1

Related Questions