簡體   English   中英

如何在 Windows 上使用 x86 perl 系統啟動 x64 shell

[英]How to launch a x64 shell using x86 perl system on windows

我使用 perl 調用system start ,我需要指定我希望我的程序綁定到的 CPU 編號。

當我使用 x86 perl 時,它會啟動 x86 cmd來運行 start 命令。 此 x86 start不接受參數0x100000000因為它超過 32 位長度。 如果我使用 x64 perl,整個事情都可以正常工作,因為 x64 perl 啟動接受0x100000000 x64 cmd

那么如何在使用 32 位 perl 時start x64 cmd來運行start命令?

細節:

首先,我驗證了 32 位 cmd shell 不接受start /affinity 100000000而 64 位 cmd shell 接受。 在 32 位 cmd shell 中,它拋出錯誤The system cannot accept the START command parameter 100000000.

然后我分別嘗試了 x64 perl 和 x86 perl,發現 x86 perl 會得到同樣的錯誤。 請參閱下面的命令。

path/to/x64/perl.exe -e "system qq{start /b /wait /affinity 100000000 my.exe}"
path/to/x86/perl.exe -e "system qq{start /b /wait /affinity 100000000 my.exe}"

有沒有什么方法可以使用 x86 perl 啟動 x64 shell 來執行啟動?

下面簡單演示一下問題:

>sp5300-x64\perl\bin\perl -e"system 'set'" | perl -ne"print if /^ProgramFiles=/i"
ProgramFiles=C:\Program Files

>sp5300-x86\perl\bin\perl -e"system 'set'" | perl -ne"print if /^ProgramFiles=/i"
ProgramFiles=C:\Program Files (x86)

差異是由於 Windows 運行C:\\Windows\\SysWOW64\\cmd.exe而不是C:\\Windows\\System32\\cmd.exe 這是透明內部翻譯的結果,而不是PATH差異,因此更明確的路徑無濟於事。

>sp5300-x86\perl\bin\perl -e"system 'C:\Windows\System32\cmd /x /d /c set'" | perl -ne"print if /^ProgramFiles=/i"
ProgramFiles=C:\Program Files (x86)

解決方案是創建一個指向cmd.exe的鏈接,然后使用它。 這繞過了 Windows 的惡作劇。

>mklink cmd64.exe "C:\Windows\System32\cmd.exe"
symbolic link created for cmd64.exe <<===>> C:\Windows\System32\cmd.exe

>sp5300-x86\perl\bin\perl -e"system 'cmd64 /x /d /c set'" | perl -ne"print if /^ProgramFiles=/i"
ProgramFiles=C:\Program Files

WOW64 模擬器的文件系統重定向器將%SystemRoot%\\system32文件系統路徑重定向到%SystemRoot%\\SysWOW64 ,其中%SystemRoot%是系統環境變量,它指的是 Windows 目錄,例如C:\\Windows

所以正常情況下,WOW64進程(運行在64位windows上的32位進程)是無法訪問system32目錄的。

但是,從 Windows Vista 開始,32 位進程可以通過將system32替換為文件路徑中的特殊別名SysNative來引用和訪問sysetm32目錄中的文件和文件夾。

要從 x86 perl 實例啟動 x64 cmd shell,您需要通過%SystemRoot%\\SysNative\\cmd.exe明確指定 64 位 cmd.exe 的路徑

Path_to_x86_perl\perl -e "system $ENV{SystemRoot}.'\sysnative\cmd.exe /x /d /c start /b /wait /affinity 100000000 my.exe'"

但是請注意,這僅適用於 WOW64 進程,因此它不能用作 Windows 下 x86 和 x64 版本的 perl 的單一單行解決方案。 但是,您可以在程序中使用以下內容:

use Config qw( %Config );
my $system = $ENV{SystemRoot} . '\\' . ( $Config{ptrsize} == 4 ? 'SysNative' : 'System32' );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM