开发者

Dynamic String x Static String

开发者 https://www.devze.com 2022-12-21 15:12 出处:网络
Im creating a Windows Service and I want to put a dynamic path in the code. But it only accepts static code.

Im creating a Windows Service and I want to put a dynamic path in the code. But it only accepts static code.

This works:

Process.Start("C:\\Program Files\\Program\\Program.exe", "-socket 12345");  

But this doesnt:

String path = "C:\\Program Files\\Program";  
String programName = "\\Program.exe";  
String fileLocation = path 开发者_运维问答+ programName;  
Process.Start(fileLocation, "-socket 12345");  

Someone can help me?


You should never concat paths. Use Path.Combine instead.

String path = @"C:\Program Files\Program";  
String programName = "Program.exe";  
String fileLocation = System.IO.Path.Combine(path, programName);
Process.Start(fileLocation, "-socket 12345");  


Your code examples result in identical calls to Process.Start. Whatever the problem is, it's not shown here.

0

精彩评论

暂无评论...
验证码 换一张
取 消