FoxPro Programming
Return value from ShellExecute
Gravatar is a globally recognized avatar based on your email address. Return value from ShellExecute
  Doug
  All
  Sep 22, 2019 @ 12:10pm

Anyone know a way to return a value from ShellExecute()?

Calling a Python script and need to capture the value returned?

Thanks, Doug

Gravatar is a globally recognized avatar based on your email address. re: Return value from ShellExecute
  Rick Strahl
  Doug
  Sep 22, 2019 @ 04:43pm

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 ---

Gravatar is a globally recognized avatar based on your email address. re: Return value from ShellExecute
  Doug
  Rick Strahl
  Sep 29, 2019 @ 10:04am

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.

Gravatar is a globally recognized avatar based on your email address. re: Return value from ShellExecute
  Rick Strahl
  Doug
  Sep 29, 2019 @ 11:28pm

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 ---

© 1996-2024