.NET Framework Developer Center > .NET Framework Forums > Dynamic Languages on .NET > Ironpython, os.system does not work correctly but does in regular Python

Answered Ironpython, os.system does not work correctly but does in regular Python

  • Tuesday, February 09, 2010 3:15 PM
     
     
    I have an output file (BuildResults.txt) which contains, you guessed it, the build results from a command line build in VC 2007.  I use a Python script to build a bunch of solutions and dump the results to BuildResults.txt.  I then use findstr to search BuildResults.txt for errors and report them to the screen. 

    Here is an example BuildResults.txt file.

    ------ Build started: Project: ADI, Configuration: Release Win32 ------
    Compiling...
    ADI.cpp
    Compiling resources...
    Microsoft (R) Windows (R) Resource Compiler Version 6.1.6723.1
    Copyright (C) Microsoft Corporation. All rights reserved.
    Linking...
    Embedding manifest...
    Build log was saved at "file://c:\Work\Tools\Instruments\ADI\BuildLog.htm"
    ADI - 0 error(s), 0 warning(s)
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

    The command to find the errors is

    findstr /c:"error(s)" BuildResults.txt | findstr /v /c:"0 error(s)"

    or in Python

    os.system('findstr /c:"error(s)" BuildResults.txt | findstr /v /c:"0 error(s)"')

    When I run this from the command line or from Python, I should not get output.  But when I run it from Ironpython, I get the following.

    >>> os.system('findstr /c:"error(s)" BuildResults.txt | findstr /v /c:"0 error(s)"')
    BuildResults.txt:ADI - 0 error(s), 0 warning(s)
    FINDSTR: Cannot open |
    FINDSTR: Cannot open findstr
    FINDSTR: Cannot open /v
    FINDSTR: Cannot open /c:0 error(s)

    Is there a way to make this work correcty in Ironpython?  It works fine with Python 2.5 (not Iron).

Answers

  • Monday, April 12, 2010 3:01 AM
     
     Answered
    I suspect you're using an older version of IronPython. At some point, it wasn't correctly running os.system calls through CMD.EXE, but it is now.

All Replies