powershell(command_string) may fail when command_string contains string delimiters
@sgougeon)
Reported by Samuel GOUGEON (BUG DESCRIPTION:
----------------
When in a powershell command some paths having spaces must be delimited/protected with quotes, theses ones must be doubled. Otherwise, an error is yielded.
ERROR LOG:
----------
--> cmdtxt = "dir """+dname+""""
cmdtxt =
dir "C:\Users\myProfile\AppData\Local\Temp\SCI_TMP_3340_\dirname with spaces"
--> powershell(cmdtxt)
ans =
!Get-ChildItem : Impossible de trouver un paramètre positionnel acceptant l'argu !
! !
!ment « spaces ». !
! !
!Au niveau de ligne : 1 Caractère : 4 !
! !
!+ dir <<<< C:\Users\myProfile\AppData\Local\Temp\SCI_TMP_3340_\dirname with space !
! !
!s !
! !
! + CategoryInfo : InvalidArgument: (:) [Get-ChildItem], ParameterB !
! !
! indingException !
! !
! + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell !
! !
! .Commands.GetChildItemCommand !
! !
! !
--> cmdtxt = "dir """""+dname+""""""
cmdtxt =
dir ""C:\Users\myProfile\AppData\Local\Temp\SCI_TMP_3340_\dirname with spaces""
--> powershell(cmdtxt)
ans =
! !
! !
! !
! !
! Répertoire : C:\Users\myProfile\AppData\Local\Temp\SCI_TMP_3340_\dirname with !
! !
! spaces !
! !
! !
! !
! !
! !
!Mode LastWriteTime Length Name !
! !
!---- ------------- ------ ---- !
! !
!-a--- 05/02/2016 23:25 33 test.txt !
! !
HOW TO REPRODUCE THE BUG:
-------------------------
dname = TMPDIR+"\dirname with spaces"
mkdir(dname)
mputl(string(rand(1,3)), dname+"\test.txt")
dir(dname)
cmdtxt = "dir """+dname+""""
powershell(cmdtxt) // => error
cmdtxt = "dir """""+dname+""""""
powershell(cmdtxt) // => OK
OTHER INFORMATION:
------------------
First report: https://www.mail-archive.com/users@lists.scilab.org/msg04307.html
Edited by Vincent COUVERT