Batch file output to network path truncates first character.

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
fuleo
Posts: 4
Joined: 17 Feb 2013 21:39

Batch file output to network path truncates first character.

#1 Post by fuleo » 04 Mar 2013 20:34

Hi guys, I have a batch file problem in here. Trying to save an output log into a networkpathed text file, but the front letter is missing... e.g "myname" becomes "yname" -> http://pastebin.com/GSWMhwm6

Code: Select all

SET destpath="\\networklogs\measure_sw_usage\extractinfo_%COMPUTERNAME%.txt"
for /f "skip=2 tokens=1,* delims=," %%A IN ('wmic computersystem get username /format:csv') DO (echo %%B >>%destpath%)


what the output should be
testdomain\username

what the output in the text file shows
estdomain\username

fuleo
Posts: 4
Joined: 17 Feb 2013 21:39

Re: Batch file output to network path truncates first charac

#2 Post by fuleo » 04 Mar 2013 20:49

Ok error resolved.

I did this.

Code: Select all

for /f "skip=2 tokens=1,* delims=," %%A IN ('wmic computersystem get username /format:csv') DO (echo %%B >>%destpath%)


Code: Select all

echo %%B>>%destpath%


can't have the spacing before >>

very strict... ~.~

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file output to network path truncates first charac

#3 Post by foxidrive » 04 Mar 2013 23:59

The space after %%b will merely be included in the file. It's not the reason why the first character was removed.

FWIW WMIC outputs text with odd line endings and trailing spaces - you need to use a workaround to parse the output correctly in some cases.

Post Reply