Use output from DOS commands in a Windows oriented perl application

This may not be as straightforward as you think if we need to support international characters. A DOS command produces its output in an OEM-defined character set, while Windows supports either ANSI or a wide character set. You will observe that using DOS strings directly in windows will result with some odd characters.

Win32 API function OemToCharBuff is designed to address this problem. Perl script below demonstrates how it can be used:

use Win32;
use Win32::API;
 "BOOL OemToCharBuff(LPCTSTR lpszSrc, LPTSTR lpszDst, DWORD cchDstLength)"
# run your DOS command
my $output = `dsquery user domainroot -name tev*`; # A Dos command example
chomp $output;
Win32::MsgBox("DOS output: $output", 0, "Before translation");
# Convert OEM  to Windows 
OemToCharBuff($output, $output, length($output));
Win32::MsgBox("WIN output: $output", 0, "After translation");