【问题标题】:Running a console command which is stored in `std::wstring`运行存储在 `std::wstring` 中的控制台命令
【发布时间】:2011-09-10 20:49:22
【问题描述】:

我有一个控制台命令,类似于:

std::wstring ConsoleCommand;
ConsoleCommand = L"c:\\somepath\\anotherpath\\program.exe -opt1 /opt2 --opt3";

我想执行这个命令。
我该怎么做?

(可能是 Win32 API 函数,或标准 C/C++ 库。)

【问题讨论】:

    标签: c++ unicode command-line console wstring


    【解决方案1】:

    必须在 Windows 上_wsystem()_wpopen()

    【讨论】:

    【解决方案2】:

    试试ShellExecute()。您可能需要 open 动词。你也可以使用CreateProcess()

    【讨论】:

    • ShellExecute 有显式版本ShellExecuteAShellExecuteW,未修饰版本采用情境TCHAR-string 参数。
    • 不确定这有什么关系。几乎所有以任何方式处理字符串/字符的 WinAPI 都有 ANSI 和 Unicode 版本。
    • 这只是帮助 OP 找到解决问题的方法的评论。她没有指定任何项目设置,所以我认为添加一些信息不会有什么坏处……
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-17
    • 1970-01-01
    • 1970-01-01
    • 2012-06-21
    • 1970-01-01
    相关资源
    最近更新 更多