Batch commands on Windows

Moosebumps crap at
Sat Jan 24 05:23:40 CET 2004

> Can you give an example of what you mean, in Perl as well as what you
> would work in Python? I couldn't quite understand what it is that you're
> to do.

OK, actually on second test, the problem is mostly with IDLE, but not
totally.  When I hit F5 under IDLE, it behaves differently with respect to
the command window then if I just run it by double-clicking on the file.

Here is an example:


set MYVAR=3
echo %MYVAR%

# the intention is to do the same thing as BatchTest.bat, but it doesn't
work under either IDLE or by double-clicking
# in particular the environment variable is not saved, and it doesn't work
if I replace os.system with os.popen

import os

os.system("set MYVAR=3")
os.system("echo %MYVAR%")

# this actually does the same thing as Python, I was mistaken.  I was
mislead by the IDLE behavior.

system('set MYVAR=3');
system('echo %MYVAR%');

The general idea is that it would be nice if there weren't any differences
between the batch file and python.  From a practical standpoint, it would
encourage a lot of people to switch from nasty batch files to Python scripts
if you could just surround the entire thing with os.batch(' ') or some
similar sort of mechanical textual substitution.  Then you could clean it up

I am aware of os.environ and such, and that is useful, but it's not really
the point.

Of course I could write a function to take a bunch of strings, write a batch
file, save the working directory, execute it, restore the current directory,
then delete the batch file, but that seems like an awful hack.  Though I
probably will do that at some point.

> > What's the deal with that?  I thought Python started out as a scripting
> > language.  And that seems like the most basic thing that a scripting
> > language should do.
> Dunno, although MS-DOS shell scripting is certainly a small subset of
> in general. Maybe with a concrete example somebody will be able to give
you a
> hand.

It is a small subset, but an important subset.  Shell scripting started
probably when people got sick of typing the same commands into the prompt.
For a language to really support shell scripting, it should provide a way of
automating the process of typing in the commands.  As in, there should be no
difference whether you're actually typing, or you're running the script.

If there is a way and I don't know about it, I would be happy to hear about
it.  But I do think it is a pretty big hole.


More information about the Python-list mailing list