Ask Your Question
1

Running batch file on Windows when start debugging

asked 2022-07-08 01:38:45 -0600

RunDeep's avatar

updated 2022-07-15 08:40:58 -0600

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?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2022-07-08 12:20:36 -0600

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.

edit flag offensive delete link more

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 -0600 )edit
0

answered 2022-07-08 07:45:16 -0600

updated 2022-07-08 07:45:31 -0600

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

edit flag offensive delete link more

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 -0600 )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 -0600 )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 -0600 )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 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2022-07-08 01:38:45 -0600

Seen: 98 times

Last updated: Jul 11