【发布时间】:2020-10-15 02:06:44
【问题描述】:
我正在尝试从 Windows 中的 C++ 程序调用“git clone”,为此我创建了一个空文件夹(使用 std::filesystem::create_directory 和 _chdir),然后我以这种方式使用 CreateProcessW:
::CreateProcessW(std::wstring(fullPath.begin(), fullPath.end()).c_str(),
const_cast<LPWSTR>(std::wstring(fullArgs.begin(), fullArgs.end()).c_str()),
nullptr,
nullptr,
TRUE,
_createNewConsole ? CREATE_NEW_CONSOLE : 0,
nullptr,
std::wstring(_path.begin(), _path.end()).c_str(),
&siStartInfo,
&piProcInfo);
但是当我这样做时,Git 会返回以下错误消息:
fatal: could not create work tree dir 'XXXX': Permission denied
但是,自从我自己创建了文件夹后,我不确定是什么问题
文件夹权限如下:
drwxr-xr-x
知道怎么解决吗?
【问题讨论】:
-
无关:为什么是
const_cast?在调用CreateProcess之前创建临时的wstring并使用它的data()成员函数来提供它。fullPath是什么类型?如果是wstring,为什么不直接使用fullPath.c_str()?您的fullArgs是否包含lpApplicationName的引用 ("") 版本? -
drwxr-xr-x与 MS-Windows 权限关系不大。右键单击目录 > 属性 > 安全性并检查运行程序的用户的有效安全性。 -
@RichardCritten OP 我猜可能在 WSL 中运行。
-
fullPath 是一个 std::string,fullArgs 是可执行文件和参数的名称,由空格分隔。关于 const_cast 这是因为 c_str() 给了我一个 const wchar_t* 而我没有设法摆脱 const
-
关于安全选项卡,我检查了权限,每个用户都有所需的一切