How to store directional arrow character in a variable
Asked Answered
C

0

1

I am capturing TCP packets using a Wireshark tool, TShark.exe. See below code example:

cd 'c:\program files\WireShark\'
.\tshark.exe -c 10
Capturing on 'Ethernet0'
1 0.000000 192.168.1.0 -> 192.168.2.0 TCP 60 49188 -> 445 [ACK]
1 0.000198 192.168.1.0 -> 22.14.2.0 TCP 60 53144 -> 3389 [ACK]

All ok so far, but now if storing in a variable:

$packets = .\tshark.exe -c 10
$packets
1 0.000000 192.168.1.0 ÅÖ% 192.168.2.0 TCP 60 49188 ÅÖ% 445 [ACK]

The directional arrows are lost and replaced with rogue characters. How can I preserve the formatting when storing in a variable?

Chau answered 6/2, 2020 at 10:42 Comment(5)
It looks like an UTF-8 Codepoint (U+2192) mixed in with plain ASCII. I have no idea how to fix that but perhaps you could use one of the other output options and work from there (json pe). What are you trying to do?Plasmolysis
This doesn't look normal, please supply more details on the OS, PowerShell version and IDE used. What happens if you try: $packets = .\tshark.exe -c 10 | Out-String?Sidneysidoma
I can reproduce this locally with tshark.exe - can you try running the following in the command prompt before you launch powershell: chcp 65001 and see if that fixes it (it did for me...)? If it does, have a read of this answer here: https://mcmap.net/q/1328984/-powershell-and-german-umlauts-in-git-branch-names for what it's doing...Eyehole
@Eyehole - fwiw - it fixes it for me too.Plasmolysis
Have a look at this answer as I believe that is the way to fix it from within PowerShell.Sidneysidoma

© 2022 - 2024 — McMap. All rights reserved.