Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

PowerShell 4.0 Start-Process adds extra space to CommandLine

$
0
0

I'm trying to register an (older) C++ Windows Service from PowerShell with this code

$ProgramDirectoryInstallBin = "c:\dev\bin"
$ServiceExe = Join-Path $ProgramDirectoryInstallBin "myservice.exe"
$Argument = "-service"
Start-Process  -FilePath "$ServiceExe" -ArgumentList $Argument -Wait -WorkingDirectory "$ProgramDirectoryInstallBin" 

It launches the program fine, but when you look at the actual Command line passed to the program, it has an extra space at the end; e.g.,  "c:\dev\bin\myservice.exe -service "

and of course the C++ command line parser (straight from the C++ Wizard IIRC) looks like 

 if (lstrcmpi(lpszToken, _T("Service"))==0)
            return _Module.RegisterServer(TRUE, TRUE);

and will skip this logic because of the trailing blank (lpszToken=="service ").

So, once I figured this out, there are  number of ways to fix it (amend the C++ program or [Diagnostics.Process]::Start or ...) but I'm wondering:

Is there some reason for parser to append the extra space?  

While writing this, I found that

&c:\dev\bin\myservice.exe -service

works fine, so we'll go with that, but I'm still feel like I'm missing something re Start-Process (or the parser in general)

???


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>