Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Running DOS commands in Python with os.system()

Avatar of Deonicus
Deonicus asked on
Microsoft DOSPython
7 Comments1 Solution6356 ViewsLast Modified:
I have created a batch file that creates a bootable BCD/etc. so that I can boot to a WIM image. The command looks like this:
for /f "tokens=3" %%a in ('bcdedit /create /d "WIM_X" /application OSLOADER') do set guid=%%a
I need to be able to run the commands in my batch file in a python script. I have tried this:

command = 'for /f \"tokens=3\" %%a in (\'bcdedit /create /d \"WIM_X\" /application OSLOADER\') do set guid=%%a'
When I execute this, the command window indicates that the env var is being set, i.e.
c:\set guid={blah-blah-blah}
However, the variable doesn't appear to be set in the environment (I run another command to "echo" the env var, and it is unset. I use os.environ.get(guid) and it is also unset).

My question is, how can I set and retrieve the value of guid within my python script?

Note, I am constrained to the environment I am in, I can't just run the batch file, I must use a python script to accomplish what I need.
for /f "tokens=3" %%a in ('bcdedit /create /d "WIM_X" /application OSLOADER') do set guid=%%a
command = 'for /f \"tokens=3\" %%a in (\'bcdedit /create /d \"WIM_X\" /application OSLOADER\') do set guid=%%a'
Avatar of Deonicus

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answers