Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从Powershell中的字符串创建数组_Python_Arrays_String_Powershell_Split - Fatal编程技术网

Python 从Powershell中的字符串创建数组

Python 从Powershell中的字符串创建数组,python,arrays,string,powershell,split,Python,Arrays,String,Powershell,Split,我通过一个字符串参数将一个字符串从Python传递到我的powershell脚本中。该字符串是我需要从一台机器复制到另一台机器的文件列表。我使用for-each循环来处理列表中的每个文件。我唯一的问题是我不知道如何用逗号分隔列表 我用来调用此脚本的python如下所示(出于安全原因,删除了一些变量) fileList='(“\\\\[computerIP]\D$\PI\u Backup\pibackup\u 23-Sep-20\u 00.15.00.txt”,“\\\[computerIP]\D

我通过一个字符串参数将一个字符串从Python传递到我的powershell脚本中。该字符串是我需要从一台机器复制到另一台机器的文件列表。我使用for-each循环来处理列表中的每个文件。我唯一的问题是我不知道如何用逗号分隔列表

我用来调用此脚本的python如下所示(出于安全原因,删除了一些变量)

fileList='(“\\\\[computerIP]\D$\PI\u Backup\pibackup\u 23-Sep-20\u 00.15.00.txt”,“\\\[computerIP]\D$\PI\u Backup\pibackup\u 23-Sep-20\u 12.15.00.txt”,“\\\\\[computerIP]\D$\PI\u Backup\pibackup\u 24-Sep-20\u 00.15.00.txt”)”
子进程.run(['powershell.exe','.\CopyFiles.ps1','-filelist:',folderPathList'-computerIP:',computerIP'-userName:',userPass:',userPass'-destPath:',destinationPath'-filepath:',sourcePath])
我在powershell中使用的循环如下所示

#Cycles through array copying files over
foreach ($file in $fileList)  
当我使用
foreach($file in-split$filelist)
时,我可以用空格分隔列表,但不允许用逗号分隔。我正在复制的一些文件的名称中可能有空格,因此我需要能够用逗号而不是空格来分隔


我也尝试过
foreach($fileList-split',')
,但这似乎只复制了数组中的最后一个文件。

我发现问题在于我用python传递文件列表的方式。我在python中以数组的形式传递值。我需要把它当作一根大绳子传递。在我像这样把它们传进来之后

#Cycles through array copying files over
foreach ($file in $fileList)  
folderPathList=”(“\\\\\[computerIP]\D$\PI\\[U备份\pibackup\[U 23-Sep-20\U 00.15.00.txt,\\\\[computerIP]\D$\PI\[U备份\pibackup\[U 23-Sep-20\U 12.15.00.txt,\\\\\\\\\[computerIP]\D$\PI\[U备份\pibackup\[U 24-Sep-20\U 00.15.00.txt”)”
与此相反:

fileList='(“\\\\[computerIP]\D$\PI\u Backup\pibackup\u 23-Sep-20\u 00.15.00.txt”,“\\\[computerIP]\D$\PI\u Backup\pibackup\u 23-Sep-20\u 12.15.00.txt”,“\\\\\[computerIP]\D$\PI\u Backup\pibackup\u 24-Sep-20\u 00.15.00.txt”)”

带分隔符的split命令开始工作。

因此您正在向PowerShell脚本传递一个参数。参数的数据类型是什么?在foreach循环的主体中是否有与问题相关的内容?如果没有,就把它从垃圾堆里扔掉question@Bill_Stewart它是一根弦,是一根弦吗?字符串是如何分隔的?如果
(不推荐),则可以编写
(foreach$fileName in($myParameter-split','){…
有关
-split
运算符的帮助主题包含许多有用信息:
关于拆分的帮助