I need to do the following:
http://stackoverflow.com/questions/15380551/paste-but-dont-execute-command-in-windows-command-prompt
(I copied the text from the site, so it is here even it isn't available anymore on the site, who knows)
My target is to show the Windows command prompt and display a command on the command line without executing it. Therefore, if I want to display the command echo Hello, I want the command prompt to be started and display:
... where _ is the blinking cursor waiting for the user to press a key.Code:C:\Windows\System32>echo Hello_
To accomplish this, I've tried either to create a shortcut to the Windows command prompt executable, that has its "Target" changed to:or a bat file containing:Code:C:\Windows\System32\cmd.exe ...
... where /k stands for:Code:cmd.exe /k ...
This makes the command prompt continue to live and not terminate the way the /c switch acts.Code:/k : Carries out the command specified by string and continues
Any idea how to achieve this result?
+ Reply to Thread
Results 1 to 18 of 18
-
-
You just need to make it look like a command line? Or does the user actually need to be able to edit the command line?
For the former you can do something like:
Code:@echo off echo|set /p =%CD%^\echo Hello pause >nul echo . echo Hello
Last edited by jagabo; 16th Feb 2016 at 09:36.
-
I need to start cmd.exe in a bat file and the command or string after ">" should be inserted but it should only be pasted, not executed.
for example "stringtest" should be inserted:
Code:C:\Users\Name>stringtest
-
my bat file looks like that:
Code:start "Testprogram" /max %windir%\system32\cmd.exe
-
You can't do that inside a batch file, you would need to remove the carriage return from the line. There are hacks that remove characters from a line, but they only work while parsing that line and that only happens because of the carriage return. Like Jagabo demonstrated, you can simulate the effect. This code will show the command on a normal looking command line and it will execute it when the user hits enter:
Code:@echo off prompt $p$g$secho$shello PAUSE >nul prompt $p$g cls echo hello
-
-
Editable like what? You should be able to use SET /P to have your user input something. Give me some details as to what you're looking to do and I'll see what I can do.
-
I want to start a program with a bat file containing:
Code:start "program" /max %windir%\system32\cmd.exe
Code:C:\Users\Name>
Code:C:\Users\Name>stringtest
Code:stringtest
For exampleCode:ipconfig -all
Code:stringtest
-
This will allow the user to add parameters to ipconfig but not change ipconfig to something else:
Code:@echo off set /p userinput=%cd%^>ipconfig ipconfig %userinput%
-
there are two problems I think, but I'd be happy to be wrong,.., just narrowing it down what you are trying to do, so there might be someone who reacts more easily if I am wrong ...
-there cannot be just line written and just wait for user input to execute it, there is always a sort of prompt, asking user what to select/or type something but point is,..... that a new batch script line written by programer executes things, one just cannot switch from running batch script line by line to manual cmd.exe prompt window
(perhaps that VBScript allows that using that SendKeys)
-that new prompt/or batch and original batch cannot just run independently. That calling cmd/batch has to exit first so that first one continues -
I think there is no way to do it with a *.bat file but I got it with a Visual Basic Script. It seems, I must be more open for other script languages. I think I must also take a look at powershell ... very impressive
-
yes, and one can generate a basic GUI's etc
using batch and wanting user to fix a line or even a menu or something I use notepad to popup a text file, user can edit that and then save it, cancel notepad window and batch script continues its script checking/parsing that notepad file ...
Code:START /WAIT "%path_notepad%" "title.ini"
-
I'm glad you found something that works. However what you are asking to do loses it's usefulness when you start replacing the previously typed command. I can see editing the command line before executing it to change/enter parameters. It's trivial using SET /P as Jagabo demonstrated. You could even make a menu to select different functions and minimize typing. Replacing the typed command is doable, but will require checks before executing making the batch a lot more complicated.
-
But you are thinking small
, small edits, limited inputs, as soon you start to think big, that could be handy, that notepad sum up pop up. Definitely batch is wrong language for that, make no mistake, if knowing VBscript or other real language it could have nice GUI, but imagine doing something that start as small utility and in years ending up as for example Blu-Ray back up system. Suddenly you realize that works just fine, not like you have to share it with someone that needs neat GUI and golden button that says START. So you have a command line utility for backing up and encoding Blu-Ray. Then after loading BD you can end up seeing this:
Code:Title 1) MKV name :The Judge ------------------------------------------------------------------------------------------------------- 1: Chapters, 15 chapters -------------------------------------------------------------------------------------------------------c:1_1_Chapters.txt ------------------------------------------------------------------------------------------------------- h264/AVC, 1080p24 /1.001 (16:9) (eac3to info) avc, 1920x1080, progressive, 23.976fps, 16:9 (mediainfo) -------------------------------------------------------------------------------------------------------v:1_2_Video.* 2: name : 2: copy track : 2: encode track :yes 2: Avisynth script: Spline36Resize(1280,720) 2: autocrop :yes 2: w_integer :4 2: h_integer :4 2: x264 cmd line :--log-level error --crf 18 --ref 6 --vbv-bufsize 30000 --vbv-maxrate 30000 ------------------------------------------------------------------------------------------------------- DTS Master Audio, English, 5.1 channels, 16 bits, 48kHz (core: DTS, 5.1 channels, 16 bits, 1509kbps, 48kHz) -------------------------------------------------------------------------------------------------------a:1_3_Audio_English_dtsma.DTSHD 3: name : 3: copy track : 3: extract core :yes 3: encode track : 3: eac3to cmd line :-640 -down6 -down24 ------------------------------------------------------------------------------------------------------- Subtitle (PGS), English -------------------------------------------------------------------------------------------------------s:1_8_Subtitle_English_PGS.sup 8: name : 8: copy track : 8: encode track :yes 8: BDsuptoSUB options :/res:auto /fps:auto /filter:lanczos3
-
Yep, you are right batch file is not the best language to do anything elaborate. I'm not saying it can't be used, it just works better with limited parameters and well defined inputs. I'm guilty of trying to use batch files for crazy stuff, but that's just 'cause I enjoy pushing it.
Your batch file does give you a nice customized log for your backups. As you mention sharing, one big issue with batch files is they often fail on other language windows. I made a nice pure batch routine to detect which drive contains a CD and save the drive letter. Worked perfect on a US windows, not on UK windows. We ended up using a small external program to set the variable. -
I try to avoid all %windir%\system32\notepad.exe but using concrete C:\Windows\System32 instead or to avoid %temp% and all these defaults or getting drive letter. So old fashion INI file is used where it is set up by user first time or after PC is changed. Like you did. Drive letter is a part of command line (it could be just a file).
Also all inputs has to go through character check, that is most challenging to troubleshoot all inputs and get warnings to prevent illegal characters to enter batch script. Some characters cannot be used in a file path, some in filename while handling in batch , some for Avisynth etc. You are right it is a just a fun. -
Similar Threads
-
using the OR command in a batch
By marcorocchini in forum Newbie / General discussionsReplies: 8Last Post: 30th Sep 2014, 17:56 -
Command Line Batch File
By agent3lephant in forum Authoring (DVD)Replies: 1Last Post: 28th Apr 2014, 11:24 -
Looking for an AviSynth command line tool for Windows
By askiplop in forum ProgrammingReplies: 8Last Post: 9th Jan 2013, 14:58 -
Which files can be accessed by Command Prompt but not Windows Explorer?
By jimdagys in forum ComputerReplies: 5Last Post: 8th Jan 2013, 06:57 -
windows 7 command line problem with the % symbol
By sonic12345 in forum Video ConversionReplies: 1Last Post: 28th Jun 2011, 14:45