0

Is it possible of a single command to two different files/devices?

echo Hello World>lpt1>con
aschipfl
  • 33,626
  • 12
  • 54
  • 99
Hola Wald
  • 53
  • 7
  • 1
    You are essentially asking for the Unix equivalent of the `TEE` command. There isn't a native tool on Windows to do that with a batch script. But if you search StackOverFlow with: `[batch-file]tee`, you might find some work arounds. – Squashman Apr 20 '20 at 17:09
  • Well it could be easy to split it into two lines or even use `&` if needed but I just wanted to know if DOS(--Windows) had any support for these things – Hola Wald Apr 20 '20 at 17:13
  • 1
    DOS didn't have it and neither does Windows cmd.exe. – Squashman Apr 20 '20 at 17:15
  • But then we would have to re-execute the command twice then – Hola Wald Apr 20 '20 at 17:20
  • 1
    So the only logical solution would be to store the output in a buffer(file) and then re-direct the both the devices one by one – Hola Wald Apr 20 '20 at 17:29
  • This superuser thread should help. Seems the answer is use Powershell. https://superuser.com/questions/74127/tee-for-windows – jwdonahue Apr 20 '20 at 18:09
  • There is a cheap batch-only solution, [I posted seven years ago](https://stackoverflow.com/a/15553922/2152082). Not ideal because it uses a temporary file, but working. – Stephan Apr 20 '20 at 18:33
  • In PowerShell, there is `Tee-Object`. – lit Apr 20 '20 at 19:21
  • There is no way that a _single command_ output to _two devices/files_ via a switch or any combination of OS features in Windows or any other OS, unless the command/program be specifically written to do that (in which a case, there is no way that such a program output to a single device/file). In Unix the TEE (like a pipeline "T") command do that. There is not any standard TEE command on Windows. – Aacini Apr 21 '20 at 08:37

1 Answers1

0

You could send the output to a variable using a one-liner:

FOR /F "tokens=*" %%g IN ('echo Hello World') do (SET VAR=%%g)

Then, you could send that to a file:

echo %VAR%>>file.txt

echo %VAR%>>file2.txt