2

Ive been messing around with batch and i wanted to try something i never have so i got to work on something small right now but something went wrong if anybody can help me, pls do.

Error msg

If u cant see it clear here is what they say

BatchFile:

@echo off set RunTimer=Call RunTimerCommand set /p Testwadom=<Test.Wadom.txt %TestWadom% pause 

TextFile:

%RunTimer% 

ErrorMsg:

'%RunTimer%' is not recognized as internal or external command, operable program or batch file 

Note: it should be making the code do call runtimercommand

3
  • Is this just a proof of concept because I can't think of any scenario where you would do that. Commented Jan 31, 2020 at 22:33
  • I have no idea what q proof concept means I don't use terms alot can u explain Commented Feb 1, 2020 at 1:15
  • 1
    en.wikipedia.org/wiki/Proof_of_concept. Note that in reality you'll never want to run user input like %TestWadom% as it'll be a major injection security issue Commented Feb 1, 2020 at 9:16

4 Answers 4

1
@echo off set RunTimer=Call RunTimerCommand set /p Testwadom=<Test.Wadom.txt call set TestWadom=%TestWadom% %TestWadom% pause 

call set does another parse of the arguments so that %RunTimer%, as read from the file, can be substituted with the value of Call RunTimerCommand.

In a similar manner. you can view the value of %RunTimer%, as read from the file, with call echo.

@echo off set RunTimer=Call RunTimerCommand set /p Testwadom=<Test.Wadom.txt call echo(%TestWadom% pause 

The ( after echo is like using . in echo. though less problematic. It can help avoid the echo is off message if Testwadom is undefined.

Sign up to request clarification or add additional context in comments.

1 Comment

kk I'll see if this will help
0

What you need is another layer of expansion, you can do that using Call:

@Echo Off Set "RunTimer=Call ThisTime" Set /P "Testwadom="<"Test.Wadom.txt" Call %TestWadom% Pause 

Alternatively you could use delayed expansion by setting up Test.Wadom.txt like this:

!RunTimer! 

and using:

@Echo Off Set "RunTimer=Call ThisTime" Set /P "Testwadom="<"Test.Wadom.txt" SetLocal EnableDelayedExpansion %TestWadom% EndLocal Pause 

Comments

0

The problem is that batch only parsed your command once. It parsed %TestWadom% to %RunTimer%, but didn't parse %RunTimer% into Call RunTimerCommand. If you could explain to us why you need to parse a variable into another variable, we could figure out a solution.

5 Comments

it's kinda hard for me to understand u but to explain what I need, I'm trying to make custom commands that u type into a command file then u have a batch that changes the commands to batch commands and runs those
I might understand u better now the reason I did it the way I did is because I'm gunna have more text in it and those each need to be converted but Im gunna have them more then once it's kinda hard to explain
I see what you're trying to do. I'll try to figure this out
This is off the top of my head:
So, instead of having an actual command line, you would have a set loop.
0

Setlocal enableDelayedExpansion Is your friend for this use.

The below example Sets commands to an array, To assign them to Distinct names you'd need to modify the For loop or Process the Array a second time to reassign them to new variable names.

Here's the example script with Ansi Character intact:

@ECHO OFF :start Set Processed=0 Set "Val=0" color 07 SETLOCAL ENABLEDELAYEDEXPANSION :DefineArrays FOR /F "tokens=* USEBACKQ Delims=#" %%c in ("target.bat") do ( Set /a "Val+=1" SET "ScreenArray[!Val!]=%%c" ) :UseObjects FOR /L %%a in (1,1,10) DO !ScreenArray[%%a]! 2>nul pause exit 

and example source: target.bat

#Mode 1000 #ECHO Testing Array #TIMEOUT 1 #MODE con: cols=50 lines=30 #ECHO Definement Of Objects #TIMEOUT 1 #MODE 1000 #ECHO For Use in Batch #TIMEOUT 1 #CALL "%userprofile%\Desktop\target.bat" Set "msg=[34mYour Message Here[0m" @ECHO %msg% TIMEOUT 1 :screen @ECHO OFF cls color 02 mode con: cols=93 lines=13 ECHO ============================================================================================ ECHO = [33mLibrary of Objects as Commands, Functions and Programs for assignment to Array Elements[32m ECHO = ECHO = [36mTesting is Complete.[32m ECHO = ECHO = [36mYou now have the tools to use arrays Within Batch.[32m ECHO = ECHO = [36mdeveloped by: [37mT3RRY.[32m ECHO = ECHO ============================================================================================[0m TIMEOUT 4 CLS GOTO :EOF 

Comments