Reputation: 1
if i run my command in PowerShell all works fine. But if i run it in cmd it doesn't work.
Background: i will create a batch that works on every system that mounts an iso and then runs an exe that needs that iso. i wanna use a batch instead of a ps1 cause i am not familiar with ps1 signing and if it runs on all systems without issues.
For PowerShell
Mount-DiskImage ((Get-Item -Path ".\" -Verbose).FullName+"\data.iso")
For cmd
PowerShell Mount-DiskImage ((Get-Item -Path ".\" -Verbose).FullName+"\data.iso")
error:
Die Zeichenfolge hat kein Abschlusszeichen: ".
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
Upvotes: 0
Views: 424
Reputation: 13578
You have to enclose your command(s) in curly brackets, prefix it with an ampersand (&
) to execute it and wrap that by quotes:
PowerShell "& {Mount-DiskImage ((Get-Item -Path .\ -Verbose).FullName+"\data.iso")}"
You can read more about how to call PowerShell with command line options here.
Upvotes: 0
Reputation: 212
The \
escape can cause problems with quoted directory paths that contain a trailing backslash because the closing quote "
at the end of the line will be escaped \"
.
To save a directory path with a trailing backslash (\)
requires adding a second backslash to 'escape the escape'
so for example instead of "C:\My Docs\"
use "C:\My Docs\\"
Upvotes: 0