Hack Forums
[Shell] Help Regarding External Console(s) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Shell] Help Regarding External Console(s) (/showthread.php?tid=4967616)

Pages: Pages 1 2


Help Regarding External Console(s) - 'Palladium - Aug 29, 2015

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.


* - White Light - Aug 29, 2015

It's literally just

%userConsole%

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


* - Ventriloquism - Aug 29, 2015

You had one job Ali 😏 To not put DO in front of %userConsole%

#Folded


* - Advertisement - Aug 29, 2015

Regarding the top bit you'd need to if /I every comman


* - 'Palladium - Aug 29, 2015

(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?


* - White Light - Aug 29, 2015

(Aug 29, 2015 10:32 PM)Ali. 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



* - Hackoo - Aug 30, 2015

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 



* - 'Palladium - Aug 31, 2015

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.


* - annikk.exe - Aug 31, 2015

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.


* - 'Palladium - Sep 1, 2015

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



* - annikk.exe - Sep 1, 2015

(Sep 1, 2015 02:25 AM)Ali. 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::


* - 'Palladium - Sep 1, 2015

(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).


* - annikk.exe - Sep 1, 2015

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?


* - 'Palladium - Sep 1, 2015

(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.


* - annikk.exe - Sep 1, 2015

(Sep 1, 2015 04:47 AM)Ali. 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