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.
2 Answers
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.
Comments
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
jeb
This does not answer the question. It shows the output of a command. Requested was to execute the output