Anyone know a way to return a value from ShellExecute()?
Calling a Python script and need to capture the value returned?
Thanks, Doug
You can't return anything from ShellExecute()
because it runs asynchronously. It's fire and forget.
You can use the CreateProcessEx()
API but I'm not sure whether you can run a script that way. If you have West Wind Tools use CreateProcessEx() in wwApi.prg
which can wait for a result and capture Console output from StdOut.
+++ Rick ---
FYI, Shellexecute was able to run Python scripts, sometimes. It would operate normally on some scripts. But on others that had added (non-native) installed modules, it bombed.
Couldn't get CreateProcessEx() to run the .py scripts.
Regarding capturing a returned value; in the python script I write the value to a file. Then in VFP, read the value from the file.
Unfortunately, I need to use the non-native modules in python. There is a .net sdk so I am now looking at using wwdotnetbridge.
I think the problem with ShellExecute likely is that it won't have the right path. It'll just try to execute from whereever you're calling. I suppose you could try changing paths, before launching then set the path back and that might help.
Ultimately I think you have to make sure that the scripts you're running can set their own environment. Like set the launching path so that path behavior is predictable for example.
+++ Rick ---