Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

Help Regarding External Console(s)

Hi fellow Batch scripters, I need some help regarding a script I'm currently coding. I want the user to enter any command in an user input field and then the script will perform that command as an system/object/internal/normal command. Also, if the command is incorrect, I want the script to not show the "The command is not recognized, blah, blah" message.

For example:

Code
@ECHO OFF
TITLE Console Demo.
:LOOP
SET /P userConsole=Command?:
DO %userConsole%
GOTO LOOP

I just need to figure out what "DO %userConsole" is in Batch. Also, if you could, please implement it in this script: http://pastebin.com/karsBCnw . And sorry for lack of activity everyone, I've been quite busy but I might come back to Batch coding someday in the next one month or so, anyway, thanks and good bye.
It's literally just

%userConsole%

That's it. No "do". You don't "DO TITLE". You don't "DO @ECHO OFF".
You had one job Ali 😏 To not put DO in front of %userConsole%

#Folded
Regarding the top bit you'd need to if /I every comman
(Aug 29, 2015 08:24 AM)White Light Wrote:  It's literally just

%userConsole%

That's it. No "do". You don't "DO TITLE". You don't "DO @ECHO OFF".

Oh, lol, I didn't think about that one.
Also, is there a way to disable the error message if a incorrect command is entered?
(Aug 29, 2015 10:32 PM)'Palladium Wrote:  Oh, lol, I didn't think about that one.
Also, is there a way to disable the error message if a incorrect command is entered?

Redirect STDERR to nul.

Code
%whateveritwasimnotbotheringtolook% 2>nul
Hi 🤝
Try something like that :

PHP Code

<?php 
@echo off
Title Console Demo 
: NOT Microsoft Windows [Version 6.1.7601]
echo.
echo 
NOT: Microsoft Windows [Version 6.1.7601]
echo 
Copyright (c) 2015 ALI Corporation. All rights reserved.
echo.
:
cmd_loop
Color 0A
echo.
set/p cmd=%userprofile%^>
cls
%cmd% 2>nul
goto cmd_loop 
Thanks WhiteLight, but how do I retrieve the output and put it into a variable? I would also like it to not output the command output at all.
Parse it! :>

Code
@ECHO OFF
TITLE Console Demo.
:LOOP
SET /P userConsole=Command?:
for /f "delims=" %%a in ('%userConsole%') do (set output=%%a)

echo %output%
GOTO LOOP

I have an echo %output% command here, I know you said you don't want it to display but it's just to show that the output is indeed now contained inside a variable.
Thanks Annikk but I have a slight problem, since I am capturing the output of that said so command and then externally outputting it, I'm actually not really executing it, how could I perform the actual command on certain commands such as the colour and title commands (and much more)? I can't think of a solution! You can test this by doing the command "title hi" It won't capture or doing anything other than echoing " ". This commands needs to be executed and logged into the console.

My code right now.
Code
@ECHO OFF
SetLocal EnableDelayedExpansion
TITLE Console V1.2 By Ali.
:START
CLS
CALL :timeConfigure
:START2
FOR /L %%A IN (1,1,24) DO (ECHO.!messageLine%%A!)
SET /A LINE=%LINE%+1
SET /p userConsole=^>
FOR /F "DELIMS=" %%C IN ('%userConsole%') DO (SET consoleOut=%%C)
SET messageLine%LINE%=%timeVar%%MODE%: %consoleOut% & GOTO START
GOTO START
:timeConfigure
SET timeVar=%TIME%
IF %timeVar:~0,2% GEQ 12 SET MODE=PM
IF %timeVar:~0,2% LEQ 11 SET MODE=AM
            GOTO START2
            :lineConfigure
            SET messageLine%LINE%=%timeVar%%MODE%: %userConsole% & GOTO START
            GOTO START
(Sep 1, 2015 02:25 AM)'Palladium Wrote:  Thanks Annikk but I have a slight problem, since I am capturing the output of that said so command and then externally outputting it, I'm actually not really executing it, how could I perform the actual command on certain commands such as the colour and title commands (and much more)? I can't think of a solution! You can test this by doing the command "title hi" It won't capture or doing anything other than echoing " ". This commands needs to be executed and logged into the console.

Actually, when you parse a command within a for loop, the command is executed.

Consider this example:
Code
@ECHO OFF
TITLE Console Demo.
:LOOP
REM SET /P userConsole=Command?:
set "userConsole=title hi"
for /f "delims=" %%a in ('%userConsole%') do (set output=%%a)

echo The command is %userConsole%
echo The output is %output%
echo Did the title of this window change?
pause
GOTO LOOP

[Image: 3XYp9rt.png]

::purr::
(Sep 1, 2015 04:14 AM)annikk.exe Wrote:  Actually, when you parse a command within a for loop, the command is executed.

Consider this example:
Code
@ECHO OFF
TITLE Console Demo.
:LOOP
REM SET /P userConsole=Command?:
set "userConsole=title hi"
for /f "delims=" %%a in ('%userConsole%') do (set output=%%a)

echo The command is %userConsole%
echo The output is %output%
echo Did the title of this window change?
pause
GOTO LOOP

[Image: 3XYp9rt.png]

::purr::
How could I output it to the console log without echoing " "? (my console script).
What is "it"?
Output what to the console log?

Also please clarify what you mean by the console log... do you mean the cmd window, or some text file?
(Sep 1, 2015 04:40 AM)annikk.exe Wrote:  What is "it"?
Output what to the console log?

Also please clarify what you mean by the console log... do you mean the cmd window, or some text file?
"it" = nothing, in your script it says "The output is ", I do not want it to display " ", I want it to display command parameter such as "TITLE Hi". The console "log" is the main script I'm working on which is in page 1 of this THREAD. When you enter something into the console in that script, it will log it and you can see it in the window.
(Sep 1, 2015 04:47 AM)'Palladium Wrote:  "it" = nothing, in your script it says "The output is ", I do not want it to display " ", I want it to display command parameter such as "TITLE Hi".

So... echo the %userConsole% variable then?


Code
@ECHO OFF
TITLE Console Demo.
:LOOP
SET /P userConsole=Command?:
for /f "delims=" %%a in ('%userConsole%') do (set output=%%a)
echo.%userConsole%
echo.%output%
GOTO LOOP


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by RoriksteadFeb 22, 2015 06:35 AM 13 432 Feb 22, 2015 06:35 AM
Last Post: Rorikstead
[.NET] by Fruit SnacksJan 24, 2015 04:04 AM 17 577 Jan 24, 2015 04:04 AM
Last Post: Fruit Snacks
[.NET] by Fruit SnacksJan 22, 2015 07:18 AM 4 201 Jan 22, 2015 07:18 AM
Last Post: Fruit Snacks