1

Okay, I have such a batchfile:

@title RUBY ;)
@set PATH=D:\Programming\Ruby22-x64\bin;%PATH%
@call cmd /K cd /D E:\RubyProgramming

that I use to facilitate running scripts without the need to navigate to the folder each time. The thing is that I usually run the very same command for hundreds of times for a given program that I am working on at any given time. For instance:

ruby rubyprogram.rb inputfile.txt outputfile.xml miscargument

Is there a way to make such a batch file that types in a command when you run it? Not executes, just type in, so that I press Enter to execute it and use ↑ up arrow to use it again in the cmd? I haven't been able to find a command that would allow this anywhere, but it would be useful if there was one.

2 Answers 2

2

The simplest would be to just create a new batch-file that executes that specific command:

@echo off
    title RUBY ;)
    set PATH=D:\Programming\Ruby22-x64\bin;%PATH%
    cd /D E:\RubyProgramming
    rubyprogram.rb inputfile.txt outputfile.xml miscargument

Alternatively, you could get the batch file to repeatedly ask for the command to run

@echo off
    title RUBY ;)
    set PATH=D:\Programming\Ruby22-x64\bin;%PATH%
    cd /D E:\RubyProgramming
    set RUBYCMD=rubyprogram.rb inputfile.txt outputfile.xml miscargument
:loop
    echo.
    REM line below ends with a space for neatness
    set /p RUBYCMD=Enter ruby command (or 'Q' to exit) [%RUBYCMD%]: 
    if /i "%RUBYCMD%" == "q" goto :eof
    %RUBYCMD%
    goto :loop
Sign up to request clarification or add additional context in comments.

Comments

2

No, batch files can't type or click anything. However, you can call scripts from a batch file which are written in other languages. For example, you cold write a VB or an AutoIt script, call it from your batch and make the new script "type" the command.

Take a look at this VB script:

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run "%windir%\notepad.exe"
WshShell.AppActivate "Notepad"

WshShell.SendKeys "hello world"

This will open notepad, focus the new window and type hello world. This way you can also start a new console or get the focus of an already started one and type your command. This code can be saved in a separate vb script file and called from your batch.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.