Git Product home page Git Product logo

Comments (4)

lord63 avatar lord63 commented on June 19, 2024

The list: ', ", &, (, ), ;, <, ```, |

from wonderful_bing.

lord63 avatar lord63 commented on June 19, 2024

Hey, I found something in the subprocess module documentation, which you can use $pydoc -p 6789 to get them.

Replacing os.system()                                                       
---------------------                                                       
sts = os.system("mycmd" + " myarg") 
==>                                                                         
p = Popen("mycmd" + " myarg", shell=True)
pid, sts = os.waitpid(p.pid, 0)           

Note: 

* Calling the program through the shell is usually not required.

* It's easier to look at the returncode attribute than the
  exitstatus.                                                               

A more real-world example would look like this:

try:                                                                        
    retcode = call("mycmd" + " myarg", shell=True)                          
    if retcode < 0:                                                         
        print >>sys.stderr, "Child was terminated by signal", -retcode
    else:                                                                   
        print >>sys.stderr, "Child returned", retcode
except OSError, e:                             
    print >>sys.stderr, "Execution failed:", e                                                

from wonderful_bing.

lord63 avatar lord63 commented on June 19, 2024

It seems that args should be a sequence of program arguments, or a string with shell set to True.

Something about shell=True, get more information from here: Frequently Used Arguments

Warning

Executing shell commands that incorporate unsanitized input from an untrusted source makes a program vulnerable to shell injection, a serious security flaw which can result in arbitrary command execution. For this reason, the use of shell=True is strongly discouraged in cases where the command string is constructed from external input:

from wonderful_bing.

lord63 avatar lord63 commented on June 19, 2024

It seems that use a sequence of program arguments as args will be a good idea, you don't have to worry about the special characters(except " if I use "blabla").

>>>subprocess.call(['echo', "Today's Picture Story"])
Today's Picture Story
0
>>> subprocess.call('echo "Today's Picture Story"', shell=True)
  File "<stdin>", line 1
    subprocess.call('echo "Today's Picture Story"', shell=True)
                                 ^
    SyntaxError: invalid syntax
>>> subprocess.call('echo "Today\'s Picture Story"', shell=True)
Today's Picture Story
0

from wonderful_bing.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.