python 系统调用的实例详解

python 系统调用的实例详解

              本文将通过两种方法对python 系统调用进行讲解,包括python使用CreateProcess函数运行其他程序和ctypes模块的实例,

一 python使用CreateProcess函数运行其他程序

>>> import win32process 
>>> handle = win32process.CreateProcess('c:\\windows\\notepad.exe','',None,win32process.CREATE_NO_WINDOW,win32process.STARTUPINFO()) 
>>> win32process.TerminateProcess(handle[0],0) 
>>> import win32event 
>>> handle = win32process.CreateProcess('c:\\windows\\notepad.exe',win32process.STARTUPINFO()) 
>>> win32event.WaitForSingleObject(handle[0],-1) 
0 
 

二 ctypes模块简介

以下代码是使用ctype模块在windows下直接调用user32.dll中的MessageBoxA函数

>>> from ctypes import * 
>>> user32 = windll.LoadLibrary('user32.dll') 
>>> user32.MessageBoxA(0,str.encode('Ctype is cool!'),str.encode('Ctype'),0) 
1 

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持

相关文章

在前一篇博客中我们介绍了加侧旋的乒乓球弧圈技术的模拟,本...
在近期conda的版本更新中,有可能会删除路径下的_sysconfigd...
本文主要展示了一些lambda表达式的使用示例,通过这些示例,...
本文通过对比Jax和Numpy计算Normalized Hamming Distance的过...
我们知道GPU加速在可并行化程度比较高的算法中,能够发挥出比...
Numpy这个库在Python编程中非常的常用,不仅在性能上补足了P...