Answered by:
Powershell cmd /c Output Truncated

Question
-
Hi folks can anyone help with this problem please?
I'm pulling output from the command below into an array, bit it's being truncated at 20 items ( or 863 characters if i change array to string )
[array]$myoutput = cmd /c perl.exe "E:\Program Files (x86)\HP\HP BTO Software\bin\nnmcommconf.ovpl" -proto snmp -host servername
returns...
SNMP Configuration Entry:
name = server.domain.com
management address = 1.1.1.1
addressForced = false
preferredVersion = null
minimum security level = Community Only (SNMPv1 or v2c)
readCommunity = obfuscate
writeCommunity = null
timeout = 5000
retries = 1
port = 161
proxyPort = null
proxyAddress = null
SNMPv3 user names = null
SNMPv3 context names = null
enabled = true
address disco enabled = true
get bulk enabled = true
region name = Private IP Addresses
node setting description = nullrunning the cmd from cmd prompt returns
SNMP Configuration Entry:
name = server.domain.com
management address = 1.1.1.1
addressForced = false
preferredVersion = null
minimum security level = Community Only (SNMPv1 or v2c)
readCommunity = obfuscated
writeCommunity = null
timeout = 5000
retries = 1
port = 161
proxyPort = null
proxyAddress = null
SNMPv3 user names = null
SNMPv3 context names = null
enabled = true
address disco enabled = true
get bulk enabled = true
region name = Private IP Addresses
node setting description = null
active address = 10.10.10.10
active readCommunity = public
active SNMPv3 user = null
active SNMPv3 context = null
sensitive data is obfuscated.
Why is there truncation ?
Thanks in advance
Steve C
Tuesday, March 18, 2014 11:06 AM
Answers
-
found it !
Unbelievable, actually Larry Weiss was close...
I'll try and explain.
The host name parameter value is case sensitive and because the first one in my list had incorrect upper case characters the perl (which runs java, don't ask!) was returning default properties applicable to any host. the 4 missing properties:
active address = 10.10.10.10
active readCommunity = public
active SNMPv3 user = null
active SNMPv3 context = nullcould only be returned for a valid node !
Tenacity points for Rhys + give me a clue points for Larry
- Proposed as answer by Al Dunbar Wednesday, March 19, 2014 1:58 PM
- Marked as answer by Steven Conner Wednesday, March 19, 2014 2:00 PM
Tuesday, March 18, 2014 3:14 PM
All replies
-
Stupid question...how are you outputting the contents? I just ran
[array]$myoutput = wmic /?
and the result, while kind of ugly because of line spacing, has all the same data as just running the command manually. And that has far more data in the output than your command.
So my stupid question is because I can't imagine how there's anything wrong with the command itself.
Tuesday, March 18, 2014 12:31 PM -
Hi Rhys
the array is just a waypoint, after I've got all the output into there I'm iterating through it pulling out only some of the properties using something like...
#($myoutput -split '[\r\n]') |% $_ {
# if ($_ -match '^node setting description' ) {
# $temp0 = $_.split("=")
# $temp0
# $objProps | add-Member -type NoteProperty -Name $temp0[0] -Value $temp0[1]
# }
#
# }
and I'll be outputting them to a text file for my customer, unfortunately 3 of the 4 lines being truncated are required.
Tuesday, March 18, 2014 12:37 PM -
Did you try a " | Out-String" at the end of your "cmd /c" ?
Http://ItForDummies.net
Tuesday, March 18, 2014 12:40 PM -
yes I have and exactly the same problem occurs. I've output to a .txt too to make sure there are no odd end of file characters but there's nothing obvious there, I know there's no buffering issues in PowerShell and I can find nothing to suggest that the default array variable initialisation would be limited to 20 items.Tuesday, March 18, 2014 12:45 PM
-
Why are you splitting the output? It should already be in an array of objects
$myoutput | %{
if ($_ - match '^node setting description') {
$temp0 = $_.split("=")
$objProps | add-member -type NoteProperty $temp0[0] $temp0[1]
}
}
If you just output $myoutput to the console after running the command you're saying the data is truncated?
- Edited by Rhys W Edwards Tuesday, March 18, 2014 12:49 PM
Tuesday, March 18, 2014 12:48 PM -
i'm splitting each array element to get the property and value either side of the "=".
"If you just output $myoutput to the console after running the command you're saying the data is truncated?"
Yes. the output in my original post is straight from my script editor powershell console
kind regards
Steve C
Tuesday, March 18, 2014 12:54 PM -
update...
I've just tried outputting to file
| Out-File c:\temp\9999.txt
and the file is truncated a the same point.
Could it be that only part of the input stream is arriving ?
Tuesday, March 18, 2014 1:30 PM -
I mean why are you splitting '[\r\n]' - not that it's related, just curious.
The input stream must be the source of the issue, no idea why though.
Why use cmd at all, did you try just running the perl command in the powershell console?
Tuesday, March 18, 2014 2:01 PM -
I suspect that the arguments to perl.exe are not being sent intact.
Can you get your perl script to echo the arguments to verify them?
Tuesday, March 18, 2014 2:06 PM -
yeah I'm just getting a handle on the PowerShell, it's the 1st time I've done anything like this. Through extensive testing to get round the truncation problem I realise now that I don't need that split, that whole bit is #commented out until I get that problem solved.
Tuesday, March 18, 2014 2:08 PM -
Unfortunately it's not my perl, it's HP supplied. The arguments must be getting sent to the perl script though otherwise that data that *is* coming back wouldn't ? The 2 arguments are both non optional, if they're not supplied the .ovpl doesn't execute
Tuesday, March 18, 2014 2:13 PM -
Try
$myoutput = start-process perl.exe -argumentlist "'E:\Program Files (x86)\HP\HP BTO Software\bin\nnmcommconf.ovpl' -proto snmp -host servername" -passthru
although just
$myoutput = perl.exe "E:\Program Files (x86)\HP\HP BTO Software\bin\nnmcommconf.ovpl" -proto snmp -host servername
should work. You don't need to cast $myoutput as an array, powershell does a lot of that minutiae for you - it knows the output is an array of lines of text, also why you don't need to split the r n.
Hope this helps, good luck!
Tuesday, March 18, 2014 2:19 PM -
found it !
Unbelievable, actually Larry Weiss was close...
I'll try and explain.
The host name parameter value is case sensitive and because the first one in my list had incorrect upper case characters the perl (which runs java, don't ask!) was returning default properties applicable to any host. the 4 missing properties:
active address = 10.10.10.10
active readCommunity = public
active SNMPv3 user = null
active SNMPv3 context = nullcould only be returned for a valid node !
Tenacity points for Rhys + give me a clue points for Larry
- Proposed as answer by Al Dunbar Wednesday, March 19, 2014 1:58 PM
- Marked as answer by Steven Conner Wednesday, March 19, 2014 2:00 PM
Tuesday, March 18, 2014 3:14 PM -
Hi Fabadoom,
It seems you have solved the issue, if you have any other questions, please let me know.
If you have any feedback on our support, please click here.
Best Regards,
Anna
TechNet Community Support
Wednesday, March 19, 2014 7:23 AM