1. DLP Flash Christmas Competition + Writing Marathon 2024!

    Competition topic: Magical New Year!

    Marathon goal? Crank out words!

    Check the marathon thread or competition thread for details.

    Dismiss Notice
  2. Hi there, Guest

    Only registered users can really experience what DLP has to offer. Many forums are only accessible if you have an account. Why don't you register?
    Dismiss Notice
  3. Introducing for your Perusing Pleasure

    New Thread Thursday
    +
    Shit Post Sunday

    READ ME
    Dismiss Notice

Batch File Question

Discussion in 'Tech Support' started by mknote, Nov 28, 2012.

  1. mknote

    mknote 1/3 of the Note Bros. DLP Supporter

    Joined:
    Apr 14, 2009
    Messages:
    1,383
    Gender:
    Male
    Location:
    Melbourne, Florida, United States
    I'm running a command line executable that sifts through data and puts it into a form that I want to use. However, it requires several inputs, and it's tedious to continuously type them in to the program, especially since several of the parameters are constant.

    The natural solution to this, I thought, was a batch file. I've had experience with them before in game modding, and it seemed like the perfect solution. Unfortunately, it doesn't seem to be working, and Googling some questions proved... unenlightening. So I decided to come here.

    When I open the EXE, the command prompt says thus:

    Enter the input file:

    Say I put in input.exe. It likes that, so it goes to the next line:

    Enter the output file:

    And so on. What I want the batch file to do is put in this stuff automatically. This code I have written so far is:

    Code:
    @echo off
    aip2phs2
    input.txt
    output.txt
    This opens the executable correctly when I run the batch file, but it doesn't input the lines, and it looks as though I've simply opened the executable itself. I know there are those on DLP much more tech savvy than I am, so I ask - how do I do this?
     
  2. wordhammer

    wordhammer Dark Lord DLP Supporter

    Joined:
    Feb 11, 2010
    Messages:
    1,918
    Gender:
    Male
    Location:
    In the wood room, somewhere flat
    If the executable is coded to accept input file and output file as parameters, you could batch it as a single command:

    aip2phs2 -i input.txt -o output.txt

    or however those parameters are accepted; run the executable with the /help or -help or /? switch to find out what parameters it accepts.

    If it doesn't allow for those parameters, you could repackage it using a tool called AutoIT. This is a simple batch-packaging tool that I've used several times over the years to fake user input for predictable interactions.

    If you want a more modern approach, I think this is a job for PowerShell, but my skills aren't developed enough to explain how.
     
  3. Rubicon

    Rubicon High Inquisitor DLP Supporter

    Joined:
    Apr 8, 2011
    Messages:
    547
    Location:
    US
    If the command accept arguments like wordhammer mentions, that's the way to go. If not, I would probably just use Python and pexpect. Something like:

    Code:
    import pexpect 
    
    program = pexpect.spawn('input.exe') 
    
    program.expect('Enter the input file:') 
    program.sendline('input.txt') 
    
    program.expect('Enter the output file:') 
    program.sendline('output.txt')
    
     
  4. World

    World Oberstgruppenführer DLP Supporter Retired Staff

    Joined:
    Apr 19, 2006
    Messages:
    3,336
    Location:
    Axis of Evil (Original)
    I know little, but I would have expected that, if you want to give the filenames as arguments to the exe, they'd need to be directly behind it, i.e.
    aip2phs2 input.txt output.txt
    if the exe accepts the parameters as such, or with more information like Wordhammer wrote.

    You can't however use batch to interact with a program that way.
     
  5. T3t

    T3t Purple Beast of DLP ~ Prestige ~ DLP Supporter

    Joined:
    Jan 21, 2011
    Messages:
    176
    Location:
    Los Angeles
    High Score:
    3,164
    As has been mentioned, batch files can't manipulate other software directly. Python or some scripting language is probably the way to go (VBS?)
     
Loading...