First time here? Check out the FAQ!
1

Running batch file on Windows when start debugging

I'm running on Win 10 with the latest Wing Pro in a virtualenv. After the venv is activated, I'd like to set some environment variables (username and password) that the script can read using os.getenv. Looking through the help files I get tantalizingly close, this looks good: "Build Command sets a command that will be executed before starting debug with this launch configuration". Unfortunately, I can't find where this is in the menus? Can this be done?

RunDeep's avatar
58
RunDeep
asked 2022-07-08 01:38:45 -0500
Wingware Support's avatar
4k
Wingware Support
updated 2022-07-15 08:40:58 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

0

The build command runs in a separate process before the debug process so can't be used to set the env directly for that process (i.e. setting the env in the build process itself won't do it), but it could set the env in a way that is then inherited by the debug process (such as system/user-wide).

To create one, go into Project Properties under the Debug/Execute tab and set the Build Command. You may want to set up the command first in the OS Commands tool and then select it from the Build Command property.

Another idea is to write an extension script that uses GetEnvironment/SetEnvironment on CAPIProject to set the env directly into Wing's Project Properties, and then execute that before debugging (either via a key binding, added menu item, or write the script so that it also starts debugging with the debug-continue or debug-file commands, via CAPIApplication's ExecuteCommand).

Wingware Support's avatar
4k
Wingware Support
answered 2022-07-08 07:45:16 -0500, updated 2022-07-08 07:45:31 -0500
edit flag offensive 0 remove flag delete link

Comments

I setup the OS command and it successfully runs when I manually trigger it (I echo the env variable to confirm it is set).

Build Command setup

OS Command

I added a print(os.getenv...) stmt before where I read the read the env vars normally, hit F5 and stop at a breakpoint right after the print and I get None in Debug I/O. Doesn't look like the build command is running, am I missing something?

RunDeep's avatar RunDeep (2022-07-08 11:51:07 -0500) edit

That's what I was trying to explain in the first paragraph above (not clearly I think) -- the build process is run and then after that Wing runs the debug process. Because the build process does not start the debug process, it does not inherit env changes made in the build process. They would have to be made system-wide somehow, which doesn't seem like a great idea. I have another idea which I'll post as a separate answer.

Wingware Support's avatar Wingware Support (2022-07-08 12:19:17 -0500) edit

Ok, thanks. Also, in the help file, Build Command is listed under the Environment tab, not the Debug/Execute tab and it also mentions a Python tab which I think is under Environment now?: link text

RunDeep's avatar RunDeep (2022-07-08 12:45:44 -0500) edit

That's the documentation for setting up launch configurations. The docs for Project Properties is at https://wingware.com/doc/proj/project...

Wingware Support's avatar Wingware Support (2022-07-08 13:23:23 -0500) edit
add a comment see more comments
1

One idea is set your Python Executable in Project Properties (or in a launch configuration if that is what you are using) to Activated Env and specify the full path to your environ.bat. That does run the .bat in a way that causes your debug process to inherit the env.

If you're using a virtualenv, have your environ.bat setup .bat also call the virtualenv's activate.bat.

If you're not using a virtualenv and Wing doesn't run the right Python then you could prepend the 'bin' directory for the Python you want to use to the to PATH env in your activate.bat.

I suspect this will solve it... please let me know if not.

Wingware Support's avatar
4k
Wingware Support
answered 2022-07-08 12:20:36 -0500
edit flag offensive 0 remove flag delete link

Comments

That did it! I am using a virtualenv. To be clear, the first statement in the batch file needed to be "call ...path to\activate.bat" followed by the set statements for the environment vars.

RunDeep's avatar RunDeep (2022-07-11 01:15:10 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer