command line batch support executable on 64 bit hardware?

Discussion in 'Software' started by JustAnotherDude, Jan 26, 2010.

  1. JustAnotherDude

    JustAnotherDude Private E-2

    I have an existing batch job that calls an old executable to do a search and replace within a text file. The executable is named XCHANGE.EXE, and is one of the old Clay's Utilities from clayruth.com

    It runs fine on Windows XP Home and XP Pro, but on a new computer running Windows 7 Pro 64 on Intel i7, the batch code works but the executable causes an error message telling me it can not run on the existing hardware.
    I tried it on a computer running Vista 64 on Intel Core 2 Duo T9550 and get the same error message.

    I'm looking for a solution. I figure there could be at least two ways to solve the problem:

    1) Learn how to use batch code to do search and replace (is it possible?).

    2) Find a newer search and replace utility that will run in command-line mode under Windows 7 on 64 bit hardware.

    Surely there are other solutions, but those are the only ones I can think of at the moment.

    Can batch code perform search and replace on text files? If so, can it handle moderately large files (some are about 40 megabytes, but most are only about 2 megabytes or less).

    I mention the file size because the existing executable utility takes several seconds to operate on the larger files (like maybe 30 seconds running on a 2.4GHz CPU). So I'm afraid that batch code would take dramatically longer to do the same job. But even so, if it would work, perhaps I would use it.
    Also, the executable is capable of replacing tab characters with space characters, removing and/or replacing page-break characters and other print-related formatting codes (typically below ASCII 31), as well as extended characters (to ASCII 255).

    Is there a command line search and replace utility that will run under Windows 7 on 64 bit hardware? That would really be ideal for me.

    Thanks in advance for any advice.
     
  2. GermanOne

    GermanOne Guest

    Hi JustAnotherDude,

    you could use FINDSTR and the variable exchange, but imho its not the best way. Its verry slow and causes errors if the text contains special characters (e.g. <>|&%^).

    How was the usage of your XCHANGE.EXE? Which parameters and options worked for you? Maybe I could write a small VBScript for you (you could call it using batch).

    Regards
    GermanOne
     
  3. JustAnotherDude

    JustAnotherDude Private E-2

    Thanks for your response. The executable XCHANGE.EXE was called from within the batch job as
    XCHANGE.EXE filename "old_text" "new_text"

    It was simple, and allowed non-standard ASCII characters to be used (control characters and "extended" characters to 0xFF).

    Anyway, I found a person locally who created a small utility that does the same thing, but this one works under Vista and Windows 7 on 64 bit hardware where the older one did not.

    Thanks again for your response. I appreciate your time.
     
  4. GermanOne

    GermanOne Guest

    Hi JustAnotherDude,

    you're welcome.
    If anybody else wants to use this VBScript I wrote for a friend some years ago:
    Save as Xchange.vbs
    Code:
    Option Explicit
    
    ' Syntax:
    ' 
    ' Xchange.vbs Filename -Option1 Old -Option2 New
    ' 
    ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ' 
    ' Option1/Option2 | Old/New
    ' ----------------|------------------------------------------------
    ' -L              | any literal expression, like a word or letter
    '                 |
    ' -C              | use VB constants:
    '                 |      "Tab"  tab
    '                 |      "CrLf" Windows line break
    '                 |      "Cr"   carriage return
    '                 |      "Lf"   line feed
    '                 |
    ' -U              | HEX code for any unicode character
    ' 
    ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ' 
    ' Example Calls:
    ' 
    ' Xchange.vbs "C:\test.txt" -l ";" -c "tab"
    ' will replace semicolons with tabs in C:\test.txt
    ' 
    ' Xchange.vbs "C:\test.txt" -u "3F" -l "!"
    ' will replace Character 3F (question mark) with exclamation marks
    ' 
    ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ' 
    ' Return Code (Errorlevel):
    ' 
    ' 2 Syntax Error
    ' 1 File not found
    ' 0 No Error
    
    On Error Resume Next
    Dim strFile, optF, xFind, optR, xReplace, fso, text
    
    If Not WScript.Arguments.Count = 5 Then WScript.Quit (2)
    
    strFile = WScript.Arguments(0)
    optF = WScript.Arguments(1)
    xFind = WScript.Arguments(2)
    optR = WScript.Arguments(3)
    xReplace = WScript.Arguments(4)
    
    Select Case UCase(optF)
      Case "-L"
      Case "-U"
        xFind = ChrW(CLng("&H" & xFind))
      Case "-C"
        If UCase(xFind) = "TAB" Then
          xFind = vbTab
        ElseIf UCase(xFind) = "CRLF" Then
          xFind = vbCrLf
        ElseIf UCase(xFind) = "CR" Then
          xFind = vbCr
        ElseIf UCase(xFind) = "LF" Then
          xFind = vbLf
        Else
          WScript.Quit 2
        End If
      Case Else
        WScript.Quit 2
    End Select
    
    Select Case UCase(optR)
      Case "-L"
      Case "-U"
        xReplace = ChrW(CLng("&H" & xReplace))
      Case "-C"
        If UCase(xReplace) = "TAB" Then
          xReplace = vbTab
        ElseIf UCase(xReplace) = "CRLF" Then
          xReplace = vbCrLf
        ElseIf UCase(xReplace) = "CR" Then
          xReplace = vbCr
        ElseIf UCase(xReplace) = "LF" Then
          xReplace = vbLf
        Else
          WScript.Quit 2
        End If
      Case Else
        WScript.Quit 2
    End Select
    
    If Not Err.Number = 0 Then WScript.Quit 2
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    text = fso.OpenTextFile(strFile, 1).ReadAll
    If Not text = "" Then
      fso.CreateTextFile(strFile).Write Replace(text, xFind, xReplace)
    End If
    Set fso = Nothing
    If Err.Number = 0 Then
      WScript.Quit 0
    Else
      WScript.Quit 1
    End If
    
    You will find the usage in the comment lines (beginning with ' ).

    Regards
    GermanOne
     
  5. sanfran_local

    sanfran_local Private E-2

    Hi GermanOne,

    Thanks for your very useful vbs script. I still use Michael Mefford's old 16-bit assembly language utility, change.com, on my XP machine but Windows 7 won't run it. I use your script to extend the command line's ability to do some tricks it didn't even know it could do. I'm attaching a small example below. This little batch file searches your entire C drive (or any other drive if you change the drive letter) to find any elusive file even if you can't remember the name exactly. Then, if you wish, it goes to that directory. On my new Sandy Bridge machine with a solid state drive, it is very fast. Give it a try. I have several more of these batch scripts... Have fun. :-D

    :: go.bat
    @echo off
    if !%*==! echo. & echo syntax: go filespec & goto end
    dir c:\"*%**" /a /s /b /-p > %tmp%\tempfil || (echo. & goto cleanup)
    find /n /v "" < %tmp%\tempfil > %tmp%\tempfile
    find "[2]c:\" < %tmp%\tempfile > nul || (xchange.vbs "%tmp%\tempfile" -l "[1]c:\" -l "#c:\" > nul & goto single)
    echo. & more < %tmp%\tempfile & echo. & set /p CHOOSE=Choose the number of the file path to go to, [X] to abort:
    find "[%CHOOSE%]c:\" < %tmp%\tempfile > %tmp%\tempfi.bat
    xchange.vbs "%tmp%\tempfi.bat" -l "[%CHOOSE%]" -l "#" & goto changes

    :single
    echo. & type %tmp%\tempfile & echo. & copy %tmp%\tempfile %tmp%\tempfi.bat > nul

    :changes
    xchange.vbs "%tmp%\tempfi.bat" -l "#c:\" -l "dir /a #c:\"
    xchange.vbs "%tmp%\tempfi.bat" -l "#" -u "22"
    xchange.vbs "%tmp%\tempfi.bat" -c "CrLf" -l "#}"
    xchange.vbs "%tmp%\tempfi.bat" -l "#" -u "22"
    xchange.vbs "%tmp%\tempfi.bat" -l "}" -c "CrLf"

    call %tmp%\tempfi.bat | find "Directory" > %tmp%\tempfile.bat
    xchange.vbs "%tmp%\tempfile.bat" -l " Directory of c:\" -l "cd /d c:\"
    echo.
    call %tmp%\tempfile.bat

    :cleanup
    del %tmp%\tempf*.*
    :end
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds