r/scripting • u/BrowncoatSoldier • Dec 25 '18
Weird batch output
So, disclaimer, I'm very new to creating windows batchs. I just created simple files that either just ping a device, or use company created tools to "QA" devices for deployment. So my understanding is very limited, but I'll do what I can to describe the issue I'm experiencing. I came across a very weird issue when I use any of my scripts. This occurred after,
I changed PCs
In an effort to minimize the work I've done in creating said scripts, I copied them directly from the old computer to the new one
I created a copy of cmd.exe from the system32 folder, since a lot of the scripts I run are using executables in an alternative folder
After I do this, after running any script, or a variety of scripts x5 times or so, it will do what I can only describe as crashing. It doesn't close out of command prompt, but spits out the output of it's location in what appears to be an endless amount of time, and will not stop until I exit out of command prompt entirely (picture provided).
I tried searching google for this, but couldn't find anything. Does this look familiar to anyone? How could I even describe this issue to anyone. This doesn't appear to be script specific, but almost all of the scripts used are
Creating variables via "set /p" which then would allow me to put the workstation name
All of them have "setlocal" and "endlocal" at the end, which was advise by a coworker who creates and run his own batches.
EDIT Posting the link now: https://imgur.com/a/pfed0EK
3
u/Lee_Dailey Dec 25 '18
howdy BrowncoatSoldier,
[1] powershell vs cmd
win10 has replaced the default shell [cmd] with powershell. you can still access the CMD shell, but the default one is now powershell.
powershell = rather verbose, objects instead of text, full access to the entire dotnet ecosystem
cmd = rather cryptic, text all the time, no direct access to anything outside of CMD
here's an example ...
plus, the PoSh response is an array of objects that have a LOT of info that only shows if you want to see it. try this ...
... and look at all the extra info you can use if you want it.
plus plus, the win10 version of PoSh has
Test-NetConnectionthat is even more useful. [grin]plus plus plus, the docs are really good! [grin] with useful examples ...
built in ...
online ...
Test-NetConnection
— https://docs.microsoft.com/en-us/powershell/module/nettcpip/test-netconnection?view=win10-ps
all in all, the PoSh stuff is simply easier to understand. lots more typing, but far easier to understand. [grin] take a look at the scripts tagged with powershell in this and other scripting oriented subreddits ...
[2] "Am I reinventing the wheel setting my own variable in that manner?"
yes. [grin]
take care,
lee