How can I ECHO the currently executing command?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

How can I ECHO the currently executing command?

#1 Post by BoQsc » 07 Jul 2022 09:15

Let's say. I want to ECHO (Display in the Command Prompt output) the:

Code: Select all

some_file.exe -flags arguments
but also execute it.

in the script:

Code: Select all

@ECHO OFF

ECHO This is some example.
some_file.exe -flags arguments             REM I want this to be shown in the output on the command line. And also execute it.

PAUSE
EXIT


aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How can I ECHO the currently executing command?

#2 Post by aGerman » 07 Jul 2022 10:20

Set the prompt empty. Then turn echo on to repeat the executed command line.

Code: Select all

@ECHO OFF

ECHO This is some example.

prompt $H
echo on
some_file.exe -flags arguments
@echo off

PAUSE
Steffen

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: How can I ECHO the currently executing command?

#3 Post by BoQsc » 07 Jul 2022 11:06

aGerman wrote:
07 Jul 2022 10:20
Set the prompt empty. Then turn echo on to repeat the executed command line.

Code: Select all

@ECHO OFF

ECHO This is some example.

prompt $H
echo on
some_file.exe -flags arguments
@echo off

PAUSE
Steffen
This introduces the unnecessary empty line in-between.

Code: Select all

This is some example.

notepad.exe -flags arguments
Press any key to continue . . .

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How can I ECHO the currently executing command?

#4 Post by aGerman » 07 Jul 2022 11:13

I didn't expect that this is much of a problem ¯\_(ツ)_/¯ If the empty line is something you can't accept, then you have to repeat the command line yourself using ECHO. Like so ...

Code: Select all

echo some_file.exe -flags arguments
some_file.exe -flags arguments
Steffen

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: How can I ECHO the currently executing command?

#5 Post by BoQsc » 07 Jul 2022 11:56

aGerman wrote:
07 Jul 2022 11:13
I didn't expect that this is much of a problem ¯\_(ツ)_/¯ If the empty line is something you can't accept, then you have to repeat the command line yourself using ECHO. Like so ...

Code: Select all

echo some_file.exe -flags arguments
some_file.exe -flags arguments
Steffen
I was pretty sure that there was a cleaner way of achieving this.
I think I've remember some piping to the ECHO command or something like that.
The results was pretty good: easily readable and simple. No additional troubles.

Thing is, the arguments and flags can change.
From the response, I think I see that I might need to start a new project to improve upon and replace the Batch scripting language.
Last edited by BoQsc on 07 Jul 2022 11:59, edited 1 time in total.

miskox
Posts: 630
Joined: 28 Jun 2010 03:46

Re: How can I ECHO the currently executing command?

#6 Post by miskox » 07 Jul 2022 11:59

Code: Select all

@echo on
?

Saso

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: How can I ECHO the currently executing command?

#7 Post by BoQsc » 07 Jul 2022 12:04

I'm not completely new to the language, only a bit rusty.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How can I ECHO the currently executing command?

#8 Post by aGerman » 07 Jul 2022 12:32

What about a subroutine geting the command line passed?

Code: Select all

@ECHO OFF

ECHO This is some example.

call :repeatAndExec some_file.exe -flags arguments

PAUSE
goto :eof

:repeatAndExec
echo %*
%*
goto :eof
Steffen

BoQsc
Posts: 92
Joined: 30 Jun 2014 04:10

Re: How can I ECHO the currently executing command?

#9 Post by BoQsc » 07 Jul 2022 13:22

aGerman wrote:
07 Jul 2022 12:32
What about a subroutine geting the command line passed?

Code: Select all

@ECHO OFF

ECHO This is some example.

call :repeatAndExec some_file.exe -flags arguments

PAUSE
goto :eof

:repeatAndExec
echo %*
%*
goto :eof
Steffen
I mean yeah, it's good enough, haven't encountered any inconsistencies in my own adaptations.

Post Reply