2011-09-18 34 views
0

我有一个读取配置文件并获取目录的C++程序。 我现在想要做的是使用配置文件中的目录设置执行.exe程序。尝试从std :: cout执行.exe

以下是一段我的代码:

int main(){ 

ConfigFile cfg("htbaseconfig.properties"); 

bool exists = cfg.keyExists("backuplocation"); 
exists = cfg.keyExists("logdir"); 
exists = cfg.keyExists("execdir"); 
exists = cfg.keyExists("fulldir"); 
exists = cfg.keyExists("incdir"); 
exists = cfg.keyExists("appdir"); 

std::string bkploc = cfg.getValueOfKey<std::string>("backuplocation"); 
std::cout << "Backup Location: " << bkploc << "\n"; 

std::string bkplogdir = cfg.getValueOfKey<std::string>("logdir"); 
std::cout << "Log Location: " << bkplogdir << "\n"; 

std::string bkpexec = cfg.getValueOfKey<std::string>("execdir"); 
std::cout << "Exec Directory: " << bkpexec << "\n"; 

std::string bkpfulldir = cfg.getValueOfKey<std::string>("fulldir"); 
std::cout << "Full Directory: " << bkpfulldir << "\n"; 

std::string bkpappdir = cfg.getValueOfKey<std::string>("appdir"); 
std::cout << "Real app Directory: " << bkpappdir << "\n\n\n"; 

for(; ;) { 

Sleep(6000); 

ShellExecute(NULL, L"open", , L"C:\\teste.htm", NULL,SW_SHOWNORMAL); 

} 

std::cin.get(); 
return (0);} 

给ShellExecute里面,我想执行以下行解析配置选项:

$execdir/program.exe $logdir/log.txt $bkpappdir $bkploc 

我该怎么办呢?我想用我在std::cout上得到的变量来执行我的程序。

+0

'的std :: string's级联,解析它们(或它们是如何解析的),虽然你因为你真的需要使用'std :: wstring's,所以会遇到麻烦。 –

回答

1

您必须将包含所有参数的字符串(c字符串,char [])传递给ShellExecute(而不是第二个NULL),就像传递给命令行一样。

所以会像

ShellExecute(NULL, L"open", , L"C:\\teste.htm", "option=param option2=param2",SW_SHOWNORMAL); 

取决于你如何从其他exe文件