1

In Windows Command Prompt (CMD), when my command1 is executed, the output is a full command (command2) with arguments. My question is, is there a way to execute command2 directly just after command1 is executed? Usually the commands could be piped like "command1 | command2". but here even the command name of command2 is a part of the output of command1. So I'm not sure if there's a way to use the pipe.

1
  • Redirect to a .cmd file. Then run the .cmd script. Commented Oct 4, 2019 at 3:46

2 Answers 2

2

I understand your question is that command1's text output is another command name - command2. If so, there's a way though not so clean. Try

> for /F "tokens=*" %a in ('first command') do %a additionalSecondCommandArg

Example. My win-10 has notepad.exe in \Windows. If I want to open aaa.txt with it,

> for /F "tokens=*" %a in ('dir /B \windows\note*.exe') do %a aaa.txt

which runs notepad.exe and trys to open aaa.txt. You can check what "tokens=*" means by typing "for /?" in command prompt.

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

Comments

0

An example for usage:
going to (CD /d) location of a file: (I named it cdwhere.cmd)

@echo off
set param=where %1
for /F "tokens=*" %%a in ('%param%') do cd /d %%~dpa
set param=

example of usage :

>cdwhere explorer
output:
>C:\Windows>_

1 Comment

This does not answer the question. It shows the output of a command. Requested was to execute the output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.