Win XP: Problem with shell scripting in Python
alanalan at newsgroup.nospam
Fri Jun 9 07:25:30 EDT 2006
"Fredrik Lundh" <fredrik at pythonware.com> wrote in message
news:mailman.6785.1149837599.27775.python-list at python.org...
> A.M wrote:
> in python, "MD" is spelled os.mkdir.
>> Am I missing anything?
> the difference between STDOUT and STDERR, and the difference between
> buffered output and non-buffered output, and perhaps a few other things
> related to how STDIO behaves on modern computers... however, if you want
> to pretend that STDOUT and STDERR are the same thing, you can use
> >>> o, i = os.popen4("md :")
> >>> i.read()
> 'The filename, directory name, or volume label syntax is incorrect.\n'
> or the subprocess module.
>> Considering the fact that Ruby doesn't have any problem with redirecting
> > STDOUT into files or string variables, is Python the right tool for
> > this kinds of shell scripting?
> rewriting BAT files as a series of os.system or os.popen calls isn't
> exactly optimal (neither for the computer nor the programmer nor the
> future user); better take an hour to skim the "generic operating system
> services" section in the library reference, and use built-in functions
> wherever you can:
> the following modules are especially useful:
> by using the built-in tools, you get better performance in many cases,
> better error handling, and code that's a lot easier to reuse (also on
> non-Windows platforms).
Thanks Fredrik for help.
The "MD :" is just a sample. The actual script contains different commands.
The actual script that I am "translating" consolidates huge table data from
multiple SQL Server database into Oracle. I have to use BCP command line at
the SQL server side and SQL*Loader at the Oracle side.
I must capture the stdout/stderr output of command lines into log files for
future inspection/troubleshooting. Beside the issue with stdout/stderror,
the main stressful problem that I have is the fact that Python captures
command line's output somehow differently. For example, popen captures BCP's
command output completely wrong. Some part of summary is at the top and the
progress percentages are at the bottom and more.! This is just stdout
I am going to investigate other popen4 and other popen forms per your
suggestion and try to fix the stdout sequence problem.
More information about the Python-list