我有一个项目,我把一个路径作为参数,并使用Tivoli Storage Manager(TSM),我执行该路径树的分段备份。 目前为止这么好。奇怪的行为使用python3 subprocess.Popen和引号之间的参数
当我尝试使用空格备份路径时,我发现了一个奇怪的行为。 当我使用TSM时,我将路径放在引号中,并且工作正常。 另一方面,在python(3.5.2)上,当我尝试使用subprocess.Popen执行命令时,tsm告诉我无法找到路径。奇怪的行为是将参数路径与当前目录连接起来。
一旦:它仅当处理具有空格的路径,即, “/ APPDATA/mtmradar/IXD /汽车ë的Ar/07_821_261_6 /”
我已经读了一些问题等16114713 hapens。
顺便说一下,我发现,当使用删除引号列表时,我可以正确执行命令。 我的问题是:为什么它连接我的当前路径与参数路径?
我在AIX 7.2上使用Python 3.5.2。 完整的命令是这样的:
>>> from subprocess import Popen
>>> with Popen(['/usr/bin/dsmc', 'i', '-quiet', '-optfile=/usr/tivoli/tsm/client/ba/bin64/dsm-NAS-SDER00019.opt', '-sub=yes', '"/appdata/mtmradar/ixd/Autos e Ar/07_821_261_6/"']) as proc:
... pass
...
这是我的了:
IBM Tivoli Storage Manager
Command Line Backup-Archive Client Interface
Client Version 7, Release 1, Level 3.0
Client date/time: 07/18/17 10:37:54
(c) Copyright by IBM Corporation and other(s) 1990, 2015. All Rights Reserved.
Node Name: NAS-SDER00019
Session established with server CELBKP03: AIX
Server Version 7, Release 1, Level 4.100
Server date/time: 07/18/17 10:38:04 Last access: 07/18/17 10:27:03
Incremental backup of volume '"/appdata/mtmradar/ixd/Autos e Ar/07_821_261_6/"'
ANS1076E The specified directory path '/usr/tivoli/tsm/client/ba/bin64/tsm_seg_bkp_python/NAS-SDER00019/"/appdata/mtmradar/ixd/Autos\ e\ Ar/07_821_261_6/"' could not be found.
执行相同的命令不带路径的双引号,我没有任何错误:
>>> with Popen(['/usr/bin/dsmc', 'i', '-quiet', '-optfile=/usr/tivoli/tsm/client/ba/bin64/dsm-NAS-SDER00019.opt', '-sub=no', '/appdata/mtmradar/ixd/Autos e Ar/07_821_261_6/']) as proc:
... pass
...
这是输出:
IBM Tivoli Storage Manager
Command Line Backup-Archive Client Interface
[...]
Incremental backup of volume '/appdata/mtmradar/ixd/Autos e Ar/07_821_261_6/'
Successful incremental backup of '/appdata/mtmradar/ixd/Autos e Ar/07_821_261_6/*'
Total number of objects inspected: 4
[...]
Total data reduction ratio: 100.00%
Elapsed processing time: 00:00:01
定义个人时,不要使用引号中的相对路径“subprocess.Popen”的参数 - 它会自动跳过你的参数,并为其运行的shell定制。 – zwer
谢谢,@ zwer。我明白那个。我唯一的dout是关于路径字符串中的当前路径。我期待着不同的东西,比如只是不了解空间。我甚至试图逃避这些空间,比如'\',但它并没有奏效。后来我发现问题是双引号。 –