是否可以使用python27.dll從CLI運行.py腳本? 我試過這個:使用python27.dll運行python腳本
rundll32.exe python27.dll,PyRun_SimpleString "import myScript.py"
但似乎不工作。
情況是,我可以安裝所需的所有python模塊,但沒有可執行文件,所以我無法安裝完整的Python。
是否可以使用python27.dll從CLI運行.py腳本? 我試過這個:使用python27.dll運行python腳本
rundll32.exe python27.dll,PyRun_SimpleString "import myScript.py"
但似乎不工作。
情況是,我可以安裝所需的所有python模塊,但沒有可執行文件,所以我無法安裝完整的Python。
你不能這樣做。爲什麼?
的Windows包含一個名爲rundll32.exe
,使您可以調用使用以下語法從32位DLL導出的函數命令行實用程序:
RUNDLL.EXE <dllname>,<entrypoint> <optional arguments>
但是,根據MSDN:
Rundll32的程序不允許你從任何DLL調用任何導出函數
[..]
這些程序只允許你從一個DLL中調用函數,這些函數被明確寫入以便被它們調用。
的dll
必須導出以下原型來支持它:
void CALLBACK EntryPoint(HWND hwnd, HINSTANCE hinst,
LPSTR lpszCmdLine, int nCmdShow);
由於python.dll
不導出這樣的入口點,你必須寫在加載DLL的C/C++的包裝應用並使用它,例如(這裏是從這樣的應用程序的一個片段):
// load the Python DLL
#ifdef _DEBUG
LPCWSTR pDllName = L"python27_d.dll" ;
#else
LPCWSTR pDllName = L"python27.dll" ;
#endif
HMODULE hModule = LoadLibrary(pDllName) ;
assert(hModule != NULL) ;
// locate the Py_InitializeEx() function
FARPROC pInitializeExFn = GetProcAddress(hModule , "Py_InitializeEx") ;
assert(pInitializeExFn != NULL) ;
// call Py_InitializeEx()
typedef void (*PINITIALIZEEXFN)(int) ;
((PINITIALIZEEXFN)pInitializeExFn)(0) ;
FILE* fp ;
errno_t rc = fopen_s(&fp , pFilename , "r") ;
assert(rc == 0 && fp != NULL) ;
[..] // go on to load PyRun_SimpleFile
if (0 == PyRun_SimpleFile(fp , pFilename)
printf("Successfully executed script %s!\n", pFilename);
產地:Awasu.com first和10教程
<<一個.dll文件無法使用rundll32.exe加載>>:我不這麼認爲,rundll32.exe完成了爲此,我想。 –
@ luca.vercelli,我現在看到我的解釋不夠清楚,所以我闡述了 –
你可以轉換成可執行文件,那麼你不需要安裝完整的python設置執行。如果你使用窗口轉換成.exe格式。檢查視頻==> https://www.youtube.com/watch?v=vPzc4OelblQ – rohitjoshi9023