gpt4 book ai didi

powershell - 如果从Cygwin调用Powershell脚本,为什么行为会有所不同?

转载 作者:行者123 更新时间:2023-12-02 23:41:41 26 4
gpt4 key购买 nike

ls
我通常从cygwin运行powershell脚本,如下所示:

$ powershell ./scriptname.ps1

它通常可以正常工作,但是今天我发现一个实例,其中从Cygwin调用脚本失败,而从powershell调用脚本成功。我有一个非常相似的脚本,在两种情况下都能成功。

该脚本可双向工作:

buildOpenSSL32.ps1
param ([string]$prefix = $(Resolve-Path .))
$adjPrefix = $prefix -replace "\\", "/"
$prefix32 = "${adjPrefix}/win32"
New-Item -ErrorAction Ignore -ItemType directory -Path $prefix32
pushd ${prefix32}/openssl-1.0.2j
write-host "Building OpenSSL for x86 into $prefix32 ..."
write-host "Configuring..."
perl Configure debug-VC-WIN32 --prefix=$prefix32
ms\do_nasm
write-host "Building..."
cmd /c "`"${env:VS140COMNTOOLS}vsvars32.bat`" && nmake /f ms\nt.mak && nmake /f ms\nt.mak install"
popd
write-host "...Done building OpenSSL for x86"

直接从powershell调用时,此脚本有效,但从Cygwin调用时失败:

buildOpenSSL64.ps1
param ([string]$prefix = $(Resolve-Path .))
$adjPrefix = $prefix -replace "\\", "/"
$prefix64 = "${adjPrefix}/win64"
New-Item -ErrorAction Ignore -ItemType directory -Path $prefix64
pushd ${prefix64}/openssl-1.0.2j
write-host "Building OpenSSL for x64 into $prefix64 ..."
write-host "Configuring..."
perl Configure debug-VC-WIN64A --prefix=$prefix64
ms\do_win64a
write-host "Building..."
cmd /c "`"${env:VS140COMNTOOLS}../../VC/vcvarsall.bat`" amd64 && nmake /f ms\nt.mak && nmake /f ms\nt.mak install"
popd
write-host "...Done building OpenSSL for x64"

错误看起来像这样:
C:\cygwin64\home\mrixman\OpenSSL5\win64\openssl-1.0.2j>perl ms\uplink-x86_64.pl nasm  1>ms\uptable.asm
Can't open perl script "ms../crypto/perlasm/x86_64-xlate.pl": No such file or directory

他们为什么要关心如何处理脚本调用?

编辑:

根据出现错误的位置,上述脚本中的相关差异似乎是 ms\do_nasmms\do_win64a
do_nasm.bat (适用于Cygwin)
perl util\mkfiles.pl >MINFO
perl util\mk1mf.pl nasm VC-WIN32 >ms\nt.mak
perl util\mk1mf.pl dll nasm VC-WIN32 >ms\ntdll.mak
perl util\mk1mf.pl nasm BC-NT >ms\bcb.mak

perl util\mkdef.pl 32 libeay > ms\libeay32.def
perl util\mkdef.pl 32 ssleay > ms\ssleay32.def

do_win64a.bat (祖 parent shell 为cygwin时出错)
perl util\mkfiles.pl >MINFO

cmd /c "nasm -f win64 -v" >NUL 2>&1
if %errorlevel% neq 0 goto ml64

perl ms\uplink-x86_64.pl nasm > ms\uptable.asm # <-- This line
nasm -f win64 -o ms\uptable.obj ms\uptable.asm
goto proceed

:ml64
perl ms\uplink-x86_64.pl masm > ms\uptable.asm
ml64 -c -Foms\uptable.obj ms\uptable.asm

:proceed
perl util\mk1mf.pl VC-WIN64A >ms\nt.mak
perl util\mk1mf.pl dll VC-WIN64A >ms\ntdll.mak

perl util\mkdef.pl 32 libeay > ms\libeay32.def
perl util\mkdef.pl 32 ssleay > ms\ssleay32.def

编辑2:

我创建了一个名为 Get-ChildItem Env:的脚本,因此我们可以看看从Cygwin调用Powershell环境(断开)时与从我的开始菜单运行(工作)时的外观有何不同。我将所有内容都转换为小写,以便区分大小写不匹配不会引起问题。

Get-ChildItem Env: diff

最佳答案

对于偶然发现本文的人,寻找答案。 ActivePerl之前的路径上很可能同时具有cygwin(或类似的)perl。

经过一段时间的研究,当我发现这个comment以及关于openssl bug跟踪器上有关版本输出的前两个注释时,我才认为它是perl的冲突版本。希望这可以节省其他人的时间。

关于powershell - 如果从Cygwin调用Powershell脚本,为什么行为会有所不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40532787/

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