从Powershell表达式向cmd传递长字符串的问题

时间:2019-03-28 16:48:26

标签: powershell batch-file cmd

我在修改从另一个堆栈溢出问题(https://stackoverflow.com/a/15885133/1683264)获取的Powershell /批处理混合脚本时遇到一些问题。

选择文件并在命令行参数中加上引号时,如果文件名和路径较短,则可以正常工作;但是,如果长度大于cmd窗口,它将分为两行。

我认为这与使用命令行参数而不是使用变量有关,但是对于批处理脚本和powershell来说我还是一个新手,我将不胜感激!

<# : chooser.bat
:: launches a File... Open sort of file chooser and outputs choice(s) to the console
:: https://stackoverflow.com/a/15885133/1683264

@echo off
setlocal


for /f "delims=" %%I in ('powershell -noprofile "iex (${%~f0} | out-string)"') do ( 

echo "%%~I"



)
pause
goto :EOF

: end Batch portion / begin PowerShell hybrid chimera #>





Add-Type -AssemblyName System.Windows.Forms
$f = new-object Windows.Forms.OpenFileDialog
$f.InitialDirectory = pwd
$f.Filter = "DAT Files (*.dat*)|*.dat*|All Files (*.*)|*.*"
$f.ShowHelp = $true
$f.Multiselect = $true
[void]$f.ShowDialog()
if ($f.Multiselect) {$f.FileNames} else {$f.FileName}

我正在寻找输出

"fullnameandpath.dat" 

但是如果我有一个长路径和文件名,我会得到这样的东西:

"fullnamea"
"
"ndpath.dat"

0 个答案:

没有答案