假设 python 中向 shell传递参数

1. testArguments = "heihei"

os.system('./test.sh   {}'.format(testArguments)); 无问题

 

2. 

testArguments = "hei     hei"

os.system('./test.sh   {}'.format(testArguments)); 

则 test.sh 接收到的第一个参数是 hei ,而不是 "hei   hei"

 

怎么修正呢?

给{}带上引号即可

os.system('./test.sh  " {}"'.format(testArguments)); 

相关文章:

  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2021-07-06
  • 2021-12-19
猜你喜欢
  • 2022-12-23
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2023-03-22
  • 2021-07-13
  • 2021-09-04
相关资源
相似解决方案