Computer Hope

Microsoft => Microsoft DOS => Topic started by: MIRKOSOFT on September 10, 2019, 07:07:58 AM

Title: How to fix command output into variable
Post by: MIRKOSOFT on September 10, 2019, 07:07:58 AM
Hi!

I tried to send command output to variable.
I'm using is in Windows 10.1903 x64
I used syntax:

Code: [Select]
SET /P variable= | command
I used batch by context menu to get word, characters and lines count in text file using old WC tool (it's great).
First I used only copying output into clipboard by:

Code: [Select]
wc %1 | clip
which output format is:

Code: [Select]
extension description.txt:  Words: 173        Lines: 31         Chars: 1195
I want also to show message with the same content by MSG command in syntax:

Code: [Select]
msg title "text"
So, finally batch code is this:

Code: [Select]
wc %1 | clip
SET /P count= | wc %1
msg Word count "%count%"
exit
But new problem - file is not found - even copy to clipboard works not and here's output:

Code: [Select]
Warning!  File: " E:\Documents\__Registry\Word Count\message.bat" not found.

      Word Count (freeware)
  TawbaWare software, August 1999
http://members.tripod.com/~tawba

Usage: WC [-w] [-c] [-l] [-a] [filename]

Options:
-w Print word count
-c Print character count
-l Print line count
-a Print grammatical analysis

If no options are entered, program displays all items,
excluding grammatical analysis.

It looks easy to see that problem is in path (I included quotes to see it).
So, Q is - how to remove first space from file path? Yes, it is possible to read %1 into variable from 2nd char, but first I checked if is %1 argument copied into variable
So, I tried this:

Code: [Select]
SET /P file= | %1
wc %file% | clip
SET /P count= | wc %file%
msg Word count "%count%"
exit

But no output, nothing. So, before cutting path I need to put file path into variable

Really if anyone know where do I mistake, please correct me.
Thank you all.
Miro