0

I have a cygwin script from which I need to launch a command in Windows command prompt. The command is quite complex (lots of parameters). The way I do it is to write a .bat file from cygwin where I put the command and launch that .bat with the command 'cygstart "$WINDIR\explorer.exe" "myBat.bat"'.

The problem is that in the cmd that is opened, I want the user to be able to run again that command, eventually changing one of the many parameters. But the command does not remain in the history.

If Windows command prompt would have had support for programatically updating the history of commands, I would have added in the .bat file the command in history before calling it and this would have saved me. But there is no such support.

So the only option I see is to have the .bat file only fill the newly opened console with the command and having the user to hit enter to execute it. This will add the command in the history and make it available for future use.

Is this possible?

aschipfl
  • 33,626
  • 12
  • 54
  • 99
Razvan L
  • 11
  • 3
  • 1
    [Related](http://stackoverflow.com/questions/38835407/add-command-to-cmd-history) and [Related](http://serverfault.com/questions/95404/is-there-a-global-persistent-cmd-history) – geisterfurz007 Jan 27 '17 at 07:03
  • Perhaps you might want to install a [`doskey` macro](http://ss64.com/nt/doskey.html)... – aschipfl Jan 27 '17 at 10:13

2 Answers2

0

Try exporting command to execute as an environment variable, in Windows we have set command to export variable.

The idea is the following:

@echo
set "command=echo something"
echo something
echo To reuse command type %command%

Like that you should be able to use %command% as abbreviation and easier to remember alternative to your long command.

geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
sarang
  • 104
  • 6
  • I like the idea, but think you should either post this as comment or add more detail to your answer to make clearer what to do :) – geisterfurz007 Jan 27 '17 at 07:05
  • Thank you for the quick response, but can you please give me more details ? – Razvan L Jan 27 '17 at 07:21
  • @RazvanL I added more to it to explain the concept :) – geisterfurz007 Jan 27 '17 at 09:28
  • The OP wants that _"the user to be able to run again that command, eventually changing one of the many parameters"_. How a parameter stored in the variable could be changed by the user? – Aacini Jan 27 '17 at 15:24
  • Do not store changing parameter in the variable, just store constant values and command in the variable. While executing command pass desired parameters. – sarang Jan 30 '17 at 04:37
0
if (@CodeSection == @Batch) @then

@echo off
rem Enter the prefill value in the keyboard buffer
CScript //nologo //E:JScript "%~F0" "Your long command goes here"
goto :EOF

@end

WScript.CreateObject("WScript.Shell").SendKeys(WScript.Arguments(0));

If you want to execute the line (besides to include it in the history), just add the {ENTER} part at end of the command. Further details at this answer. For more SendKeys keys, see here.

Community
  • 1
  • 1
Aacini
  • 65,180
  • 12
  • 72
  • 108