The Notebook Review forums were hosted by TechTarget, who shut down them down on January 31, 2022. This static read-only archive was pulled by NBR forum users between January 20 and January 31, 2022, in an effort to make sure that the valuable technical information that had been posted on the forums is preserved. For current discussions, many NBR forum users moved over to NotebookTalk.net after the shutdown.
Problems? See this thread at archive.org.

    Command-Line Woes

    Discussion in 'Windows OS and Software' started by Stunner, Feb 1, 2010.

  1. Stunner

    Stunner Notebook Deity

    Reputations:
    154
    Messages:
    1,141
    Likes Received:
    0
    Trophy Points:
    55
    Ey guys, I have a python script that merges a bunch of files together via the "python fileMerge.py <merged filename> <file(s)>" command in terminal/command-line. I would like to specify all files that have a a file extension of "log". I could do this in terminal with "python fileMerge mergedLog.txt *.log" but when I try doing that in Windows I get a complaint saying that "*.log" is not a file. If anyone could help me with this that would be great. If it were only a handful of files I wanted to specify I would have no problem just typing them out but there are a good 50 or so files I want to merge so that's why this is kind of essential to me. Thanks!
     
  2. Pirx

    Pirx Notebook Virtuoso

    Reputations:
    3,001
    Messages:
    3,005
    Likes Received:
    416
    Trophy Points:
    151
    You don't need Python for a trivial job like this. Simply use the command prompt, and do something along the lines of "type *.log > all-log.txt".
     
  3. swarmer

    swarmer beep beep

    Reputations:
    2,071
    Messages:
    5,234
    Likes Received:
    0
    Trophy Points:
    205
    Pirx is correct, and his solution is the best for your immediate problem (as I understand it)... but you may still want to understand why wildcards don't behave in Windows like they do in Unix. See, in Unix (and Linux), the shell expands the wildcards before giving it to the executable (or script). So when you type:

    python fileMerge.py *.log

    then the shell changes it to something like:

    python fileMerge.py file1.log file2.log file3.log file4.log

    ...and then runs the command.

    The Windows command shell doesn't do that. Windows just passes the wildcard straight through to the scriptm and the script gets *.log as its argument, and interprets that however it likes.

    You can see this difference easily by running:

    echo *.log

    on both platforms. On Unix it lists all the files matching the wildcard in the current directory. In the Windows shell, it'll just output " *.log " literally.

    One workaround is to install cygwin. This will let you run Unix shells such as bash inside Windows... so you'll get the Unix-style wildcard expansion. Another solution is to modify your python script to interpret and expand the wildcard... which is the way that built-in Windows shell commands work.

    For some commands, it works to concatenate the files using the "type" command (similar to "cat" in Unix) before running the script... such as "type *.log | somescript" will feed the contents of all the log files smooshed together on standard input to the script... similarly to "cat *.log | somescript" on Unix. However, whether this will do what you need or not depends on the nature of the command.
     
  4. Pirx

    Pirx Notebook Virtuoso

    Reputations:
    3,001
    Messages:
    3,005
    Likes Received:
    416
    Trophy Points:
    151
    Very nice explanation, swarmer. While we are talking about simple solutions, I just did a quick search, and it seems there's lots of freeware utilities available that can also merge text files for you. Just bing "Windows file merge". For people who are afraid of the command line, those might be a good choice as well.
     
  5. Stunner

    Stunner Notebook Deity

    Reputations:
    154
    Messages:
    1,141
    Likes Received:
    0
    Trophy Points:
    55
    Ah thanks fellas. The "type *.log > all-log.txt" did the trick and yes Swarmer, I was going to ask why the command-line doesnt behave like the terminal, but you already answered that for me. Thanks again! I'll post back here if I have any further problems/questions.