Код: Выделить всё
void Terminal::createProcessCMD(const std::wstring& path)
{
STARTUPINFOW PSTARTUPINFO;
PROCESS_INFORMATION PPROCESSINFO;
SECURITY_ATTRIBUTES SECURITYATTR;
SECURITYATTR.nLength = sizeof(SECURITY_ATTRIBUTES);
SECURITYATTR.bInheritHandle = TRUE;
SECURITYATTR.lpSecurityDescriptor = NULL;
CreatePipe(&CMD_READ, &PARENT_WRITE, &SECURITYATTR, 0);
ZeroMemory(&PSTARTUPINFO, sizeof(STARTUPINFO));
PSTARTUPINFO.cb = sizeof(STARTUPINFO);
PSTARTUPINFO.hStdInput = CMD_READ;
PSTARTUPINFO.dwFlags |= STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
PSTARTUPINFO.wShowWindow = SW_SHOWNORMAL;
BOOL success = CreateProcessW(path.c_str(),
NULL,
NULL,
NULL,
TRUE,
CREATE_NEW_CONSOLE,
NULL,
NULL,
&PSTARTUPINFO,
&PPROCESSINFO);
}
void Terminal::sendCommandToCMD(const std::wstring& command)
{
DWORD bytesToWrite = static_cast((command.size() + 1) * sizeof(wchar_t));
DWORD bytesWritten = 0;
WriteFile(PARENT_WRITE, command.c_str(), bytesToWrite, &bytesWritten, NULL);
}
int main()
{
terminal.createPrecessCMD(L"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe");
terminal.sendCommandToCMD(L"cd \'C:\\Users\\Forty\'");
}
Код: Выделить всё
PS C:\Users\Forty\AppData\Roaming\TerminalsThisWay> cd 'C:\Users\Forty'
: The term '' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ cd 'C:\Users\Forty'
+ ~
+ CategoryInfo : ObjectNotFound: (:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Код: Выделить всё
PS C:\Users\Forty\AppData\Roaming\TerminalsThisWay> cd 'C:\Users\Forty'
c : The term 'c' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ cd 'C:\Users\Forty'
+ ~
+ CategoryInfo : ObjectNotFound: (c:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Подробнее здесь: https://stackoverflow.com/questions/792 ... via-a-pipe
Мобильная версия