Hi,
my question is, how to Run a Python Script via a File or the Shell? I have Python Script with MessageBox, I need to run the script from my MASM program, at the same time, the message from MessageBox, must somehow be read from a python script to my MASM program. CreateProcess and Winexec, these commands do not work, and outputs the message PE format is not valid. How can we solve these two issues ?!
Py Script import ctypes # An included library with Python install.
def Mbox(title, text, style):
ctypes.windll.user32.MessageBoxA(0, text, title, style)
Mbox('Your title', 'Your text', 0)
## Styles:
## 0 : OK
## 1 : OK | Cancel
## 2 : Abort | Retry | Ignore
## 3 : Yes | No | Cancel
## 4 : Yes | No
## 5 : Retry | No
## 6 : Cancel | Try Again | Continue
http://www.masmforum.com/board/index.php?PHPSESSID=786dd40408172108b65a5a36b09c88c0&topic=14824.0
Old board post on running external app - might help.
OOPS: didn't see the PE issue.... sorry
py2exe
py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.
Quote from: Raistlin on May 13, 2015, 07:36:38 PM
http://www.masmforum.com/board/index.php?PHPSESSID=786dd40408172108b65a5a36b09c88c0&topic=14824.0
Old board post on running external app - might help.
OOPS: didn't see the PE issue.... sorry
py2exe
py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.
Thank you! Unfortunately this method is too bad, I had already tried it, there is a huge problem with compatibility. These tools are not perfect.
C:\Python31\SCRIPTS>build_exe MessageBox.py
Traceback (most recent call last):
File "C:\Python31\SCRIPTS\build_exe-script.py", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
C:\Python31\SCRIPTS>build_exe MessageBox.py
Traceback (most recent call last):
File "C:\Python31\SCRIPTS\build_exe-script.py", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
C:\Python31\SCRIPTS>build_exe MessageBox.py
Traceback (most recent call last):
File "C:\Python31\SCRIPTS\build_exe-script.py", line 9, in <module>
load_entry_point('py2exe==0.9.2.2', 'console_scripts', 'build_exe')()
File "build\bdist.win32\egg\pkg_resources\__init__.py", line 552, in load_entr
y_point
File "build\bdist.win32\egg\pkg_resources\__init__.py", line 2672, in load_ent
ry_point
File "build\bdist.win32\egg\pkg_resources\__init__.py", line 2345, in load
File "build\bdist.win32\egg\pkg_resources\__init__.py", line 2351, in resolve
File "C:\Python31\lib\py2exe\__init__.py", line 9, in <module>
patch_distutils()
File "C:\Python31\lib\py2exe\patch_distutils.py", line 68, in patch_distutils
from . import distutils_buildexe
File "C:\Python31\lib\py2exe\distutils_buildexe.py", line 91, in <module>
from . import runtime
File "C:\Python31\lib\py2exe\runtime.py", line 3, in <module>
from .dllfinder import Scanner, pydll
File "C:\Python31\lib\py2exe\dllfinder.py", line 7, in <module>
from importlib.machinery import EXTENSION_SUFFIXES
ImportError: cannot import name EXTENSION_SUFFIXES
C:\Python31\SCRIPTS>
Could it not be that your missing a module - I understand this actually happens allot see:
http://stackoverflow.com/questions/7446187/no-module-named-pkg-resources
Quote from: Raistlin on May 13, 2015, 10:17:16 PM
Could it not be that your missing a module - I understand this actually happens allot see:
http://stackoverflow.com/questions/7446187/no-module-named-pkg-resources
I have these modules installed. The last lines are important message to build
Quotefrom importlib.machinery import EXTENSION_SUFFIXES
ImportError: cannot import name EXTENSION_SUFFIXES
This is a compatibility problem, for which there is no solution other than downgrade py2exe, what does not make sense, because I'm working on windose 8.1 and with Python 3.1 :(
http://stackoverflow.com/questions/24237385/no-module-named-machinery (http://stackoverflow.com/questions/24237385/no-module-named-machinery)
Hello World from Python3. What exactly do you want to achieve?
include \masm32\MasmBasic\MasmBasic.inc ; download (http://masm32.com/board/index.php?topic=94.0)
includelib \Python34\libs\python34.lib ; adjust path according to your installation
Py_Initialize PROTO C
Py_Finalize PROTO C
PyRun_SimpleString PROTO C :DWORD
Init
call Py_Initialize
fn PyRun_SimpleString, "print('Hello World')"
call Py_Finalize
Exit
end start
Quote from: jj2007 on May 13, 2015, 11:20:13 PM
Hello World from Python3. What exactly do you want to achieve?
include \masm32\MasmBasic\MasmBasic.inc ; download (http://masm32.com/board/index.php?topic=94.0)
includelib \Python34\libs\python34.lib ; adjust path according to your installation
Py_Initialize PROTO C
Py_Finalize PROTO C
PyRun_SimpleString PROTO C :DWORD
Init
call Py_Initialize
fn PyRun_SimpleString, "print('Hello World')"
call Py_Finalize
Exit
end start
I have a text analyzer specially sharpened for Data Mining. It displays error messages during the parsing using messagebox. I want to do profiler using Assembler, that will handle database errors, and run the script to continuing analysis. Therefore, I need these features.
P.S. MessageBox I redirected to a text file with my name. But run the script from the program fails.
it worked! Thank you for the help! There is a solution
include \masm32\include\masm32rt.inc
.data
CmdLine db 'C:\MessageBox.py',0
.data?
handle dd ?
.code
start:
main proc
LOCAL sui:STARTUPINFO
LOCAL pi:PROCESS_INFORMATION
invoke memfill,ADDR sui,SIZEOF sui,0 ; fill STARTUPINFO
mov sui.cb,SIZEOF sui ;
fn CreateProcess,0,addr CmdLine,0,0,0,CREATE_NEW_PROCESS_GROUP or NORMAL_PRIORITY_CLASS,0,0,ADDR sui,ADDR pi
ret
main endp
END start
Python and Masm are 'incompatible'.. you're wasting your time here ;)
Quote from: LiaoMi on May 14, 2015, 01:13:03 AMit worked! Thank you for the help! There is a solution
Are you sure? On my Win7-64 system, CreateProcess returns "invalid parameter", not surprisingly because MessageBox.py is not an executable. ShellExecute would be the appropriate function.
If you need to work with the output of the Python script, Launch$() (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1047) is one solution:
include \masm32\MasmBasic\MasmBasic.inc
Init
Let esi="Python output=["+Launch$("cmd.exe /c \Python34\MyScript.py")+"]"
Inkey esi
Exit
end start
Another option is to redirect Python output to an edit control:
Launch "cmd /c SomeScript.py", SW_MINIMIZE, cb:hMyEdit
Quote from: jj2007 on May 14, 2015, 10:09:49 AM
Quote from: LiaoMi on May 14, 2015, 01:13:03 AMit worked! Thank you for the help! There is a solution
Are you sure? On my Win7-64 system, CreateProcess returns "invalid parameter", not surprisingly because MessageBox.py is not an executable. ShellExecute would be the appropriate function.
If you need to work with the output of the Python script, Launch$() (http://www.webalice.it/jj2006/MasmBasicQuickReference.htm#Mb1047) is one solution:
include \masm32\MasmBasic\MasmBasic.inc
Init
Let esi="Python output=["+Launch$("cmd.exe /c \Python34\MyScript.py")+"]"
Inkey esi
Exit
end start
Another option is to redirect Python output to an edit control:
Launch "cmd /c SomeScript.py", SW_MINIMIZE, cb:hMyEdit
Hello! I'm sorry! Yesterday I have copied from fatigue wrong file. Indeed, without the command line does not work! Thank you for your example on MasmBasic. On win 8.1 this set of macros probably not tested? RichMasm program fails - Unhandled exception at 0x00FF14BD in RichMasm.exe: 0xC0000005: Access violation writing location 0xB02DF268. In compatibility mode with Win7 also not working. Here's my original solution -
include \masm32\include\masm32rt.inc
.data
CmdLine1 db 'C:\Windows\system32\cmd.exe',0
CmdLine2 db '/C C:\MessageBox.py',0
.data?
handle dd ?
.code
start:
main proc
LOCAL sui:STARTUPINFO
LOCAL pi:PROCESS_INFORMATION
invoke memfill,ADDR sui,SIZEOF sui,0 ; fill STARTUPINFO
mov sui.cb,SIZEOF sui ;
fn CreateProcess,addr CmdLine1,addr CmdLine2,0,0,0,CREATE_NEW_PROCESS_GROUP or NORMAL_PRIORITY_CLASS,0,0,ADDR sui,ADDR pi
ret
main endp
END start
Quote from: K_F on May 14, 2015, 08:23:00 AM
Python and Masm are 'incompatible'.. you're wasting your time here ;)
They should not be compatible, it is a modular programming, until the complexity of the architecture has not exceeded the threshold of incomprehension, all should be well. Some tools suitable for certain tasks, while others are suitable for others. :t
Quote from: LiaoMi on May 14, 2015, 08:01:15 PMOn win 8.1 this set of macros probably not tested? RichMasm program fails - Unhandled exception at 0x00FF14BD in RichMasm.exe: 0xC0000005: Access violation writing location 0xB02DF268. In compatibility mode with Win7 also not working.
Thanks a lot for the feedback :t It seems I'll need a Win 8.1 machine to test my stuff. The MasmBasic code should assemble also in qEditor, RichMasm is convenient if it works (and it does work on XP and Win7-64), but it's not necessary to assemble the code.