I've just noticed that if I take the OP's code out of the batch file, it works ok (no faults) though it still returns the wrong string.
Also, if I replace the OP's code in the batch file with:
use Win32::API;
$function = new Win32::API("kernel32", "GetCommandLine", '', 'P');
$string = $function->Call();
print "string[".length($string)."] = '$string'\n";
then the batch file runs without error and $string no longer contains the additional trailing space - ie Win32::API and Inline are in complete agreement.
A problem with the Import method perhaps ? ... I've never trusted it.
Cheers,
Rob
Update: As
BrowserUk has subsequently demonstrated, it's the
pack('Z*', ...) that leads to the extra trailing space - nothing to do with Win32::API->Import() at all.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.