kiddo
kiddo

Reputation: 1626

Problem referring to the exe path in _wsystem() in Windows XP

I am having problem referring to the file path in Windows XP (SP2). Actually I want to run an exe file from a specified path say "C:\users\rakesh\Documents and settings\myexe.exe" in my program...I am using the function _wsystem("C:\users\rakesh\Documents and settings\myexe.exe") to run the file.. The problem is that it is not recognizing the space, so I went through some articles and I found an solution for that. I tried using the solution below ..it worked great:

C:\\users\\rakesh\\Docume~1\\myexe.exe

in the above after the first 6 chars I used "~1" to accomplish the rest...but it's not working when exe name is with space like below:

C:\\users\\rakesh\\Docume~1\\my exe.exe

and also I can't replace them with "~1"(not working for exe name).

How do you execute programs when there are spaces in the path or executable file name?

Upvotes: 0

Views: 391

Answers (1)

wallyk
wallyk

Reputation: 57784

Just like on the command line, the spaces need to be inside double quotes:

_wsystem (L"\"C:/users/rakesh/Documents and settings/myexe.exe\"");

Note that forward slashes work just fine for path delimiters.

Upvotes: 4

Related Questions