gpt4 book ai didi

string - PowerShell字符串串联给出了换行符

转载 作者:行者123 更新时间:2023-12-03 01:21:33 29 4
gpt4 key购买 nike

注意:Java / Closure Compiler的实际错误来自 --js-outputfile 中缺少的t!
我有以下PowerShell脚本:

cls
$jsFiles = @();

Get-ChildItem | Where {$_.PsIsContainer} | Foreach {
$dir = $_.FullName;
$jsFile = $dir + "\" + $_.Name + ".js";
if (Test-Path ($jsFile)) {
$jsFiles += $jsFile;
}
}

$wd = [System.IO.Directory]::GetCurrentDirectory();

# Build Closure Compiler command line call
$cmd = @("-jar $wd\..\ClosureCompiler\compiler.jar");

Foreach ($file in $jsFiles) {
# Both insert a newline!

$cmd += "--js $file";
#$cmd = "$cmd --js $file";
}


$cmd = "$cmd --js_ouput_file $wd\all.js";

Invoke-Expression "java.exe $cmd"
问题是在每个 +=$cmd = "$cmd str"调用上都插入了换行符!
Echoargs给我这个输出:
Arg 0 is <-jar>
Arg 1 is <S:\ome\Path\compiler.jar>
Arg 2 is <--js>
Arg 3 is <S:\ome\Path\script1.js>
Arg 4 is <--js>
Arg 5 is <S:\ome\Path\script2.js>
...
Arg 98 is <--js_ouput_file>
Arg 99 is <S:\ome\Path\all.js>
因此(可能),我从 java.exe收到一些错误:
java.exe : "--js_ouput_file" is not a valid option
At line:1 char:1
+ java.exe -jar ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: ("--js_ouput_file" is not a valid option:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

最佳答案

尝试重写为简单得多的版本:

cls

$wd = [System.IO.Directory]::GetCurrentDirectory();

# Build Closure Compiler command line call
$cmd = "-jar $wd\..\ClosureCompiler\compiler.jar";

$arrayOfJs = Get-ChildItem -Recurse -Include "*.js" | % { "--js $_.FullName" };

$cmd += [string]::Join(" ", $arrayOfJs);

Invoke-Expression "java $cmd --js_ouput_file $wd\all.js"

关于string - PowerShell字符串串联给出了换行符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12120623/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com