Bootstrap

subprocess shell=True的测试

最近用到了python的subprocess模块,看到官方声明里说要尽力避免使用shell=True这个参数,于是测试了一下:

  from subprocess import call
  import shlex

  cmd = "cat test.txt; rm test.txt"
  call(cmd, shell=True)

运行之后:
1:打开并浏览了test.txt文件
2:删除了test.txt文件

  from subprocess import call
  import shlex

  cmd = "cat test.txt; rm test.txt"
  cmd = shlex(cmd)
  call(cmd, shell=False)

运行之后:
1:尝试打开名为text.txt;的文件
2:尝试打开名为r

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。