- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
#include <stdio.h>
#include <windows.h>
#pragma warning(disable : 4996)
int main(int argc, wchar_t** argv)
{
DWORD bytes_read;
WCHAR* buffer[4096];
LPWSTR str;
STARTUPINFO start_info = { 0 };
PROCESS_INFORMATION process_info = { 0 };
ReadFile(GetStdHandle(STD_INPUT_HANDLE), buffer, 4096, &bytes_read, NULL);
str = malloc(bytes_read);
memcpy(str, buffer, bytes_read);
// debug - stdout + file
wprintf(L"\nTrying to run -> \"%LS\"", str);
FILE *f = fopen("file.txt", "w");
fwprintf(f, L"%LS", str);
fclose(f);
BOOL result = CreateProcessW(
NULL,
str,
NULL,
NULL,
TRUE,
CREATE_NO_WINDOW | NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&start_info,
&process_info
);
if (!result) {
DWORD err = GetLastError();
WCHAR *errstr;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, err,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&errstr, 0, NULL
);
wprintf(L"\nError -> %ls", errstr);
return 1;
}
return 0;
}
运行它会产生以下结果
C:\Users\Admin\source\repos\ConsoleApplication1\Debug
λ php -r "echo \"C:\\Windows\\System32\\PING.EXE\0\";"|ConsoleApplication1.exe
Trying to run -> "C:\Windows\System32\PING.EXE"
Error -> The system cannot find the file specified.
看来它使用了正确的输入。同样在 file.txt 中,在十六进制编辑器中查看时似乎没有任何可疑之处
当像下面这样硬编码 str 而不是使用 stdin 时
wchar_t cmd[] = L"C:\\Windows\\System32\\PING.EXE";
有效。
我需要做什么才能使 CreateProcessW 使用标准输入输入?
最佳答案
WCHAR* buffer[4096];
这将创建一个字符串数组。您只需要一个宽字符缓冲区。
使用L"%s"
格式说明符进行测试:
wprintf(L"%s\n", buffer)
如果可能,将 Unicode 文本作为命令行传递,示例
php -r "echo \"Test...\0\";"|app.exe Unicode
Unicode 文本可以包含 UTF16 字符集。
int main(void)
{
wprintf(L"GetCommandLineW %s\n", GetCommandLineW());
DWORD bytes_read = 0;
char buffer[4096] = { 0 };
ReadFile(GetStdHandle(STD_INPUT_HANDLE), buffer,
sizeof(buffer), &bytes_read, NULL);
int codepage = CP_UTF8;//or CP_ACP
int wlen = MultiByteToWideChar(codepage, 0, buffer, -1, 0, 0);
wchar_t *wstr = malloc(wlen * 2);
MultiByteToWideChar(codepage, 0, buffer, -1, wstr, wlen);
wprintf(L"pipe %s\n", wstr);
free(wstr);
return 0;
}
关于带有通过标准输入传递的目标的 CreateProcessW - 找不到目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53908208/
VS10、MBCS、Unicode 预处理器定义。浏览了 Google 博士的案例手册后,最好的帮助是 here ,但它并没有完全解决这个特定的问题。考虑这段代码,其中 thisexePath 是可执
#include #include #pragma warning(disable : 4996) int main(int argc, wchar_t** argv) { DWORD b
我找不到确切的答案,所以我决定问一下。 我一直在阅读“Windows 内部调试”,在示例中它告诉我在 上设置断点kernel32!CreateProcessW . 但在此之前它使用 .symfix d
我目前将应用程序转换为使用 CreateProcessW() 而不是 Runtime.exec(),因为我需要它提供的信息。但是,对 CreateProcessW() 的任何调用都会失败,并显示错误代
我想在 C 程序中执行 TEST.exe。当我使用 system( "TEST.exe output-file" ); 我能得到我所期望的。 但是当我使用以下代码时 CreateProcessW()
如何在Linux中使用“CreatePipe”和“CreateProcessW”功能,当我在Linux中编译C++代码时,出现一些错误,如下所示:在此范围内未声明“CreatePipe”。未在此范围内
我正在尝试弄清楚如何从我用 CreateProcessW 创建的进程。我看了文档,用谷歌搜索并搜索了这个列表,但我没有找到好的建议/样本然而 :) 这是我到目前为止的想法(它在 Windows 上运行
我有一个简单的代码,它使用 system() 通过变量 %APPDATA% 将文件下载到 AppData,我想使用 CreateProcessW 而不是系统,但出于某种原因,当我在 CreatProc
运行以下代码后,一切都按照我的意愿进行,除了文件夹显示:test2﷽﷽ꮫꮫꮫꮫﻮﻮﻮ 这是怎么回事? std::string arrString[3] = {" /C mkdi
CreateProcessW failed 193 Unhandled exception: ProcessException: %1 is not a valid Win32 application
我需要创建一个进程,并获得它的句柄和ID。。以下是我的代码:。它在输出窗口中输出“无法创建进程”。我在Process Explorer中看不到进程,PI的所有值仍然为0。。它还给我一条消息:在PEX.
我试图让 CreateProcess 或 CreateProcessW 执行名称 \foo.exe. arg_string 包含 "\foo.exe"foo si 设置如下: memset(&si,0
这就是我正在做的,而且我不断得到这个: 我试过: 在 GitHub 上检查我的 ssh key ,生成新的 从 https://git-scm.com/download/win 卸载和安装 Git 从
本质上,我想创建一个新进程并从父进程为其定义环境。我想使用 CreateProcessW并将(修改后的)UNICODE 环境传递到 lpEnvironment,但我不确定与 ANSII 环境 bloc
我知道 startup_info 是指向 STARTUPINFO 结构的指针 我有一个函数,我通过引用将 startup_info 传递给它。所以我们可以说我正在通过引用传递一个指针 void cp(
即使我设置了 flutter C:\flutter\bin 的路径,我在运行时也遇到了错误 flutter doctor command CreateProcessW 失败 5 哎呀; Flutter
我运行以下 C 代码来创建一个进程。 exe文件位于C:\Program Files\Exes\Start\process1.exe CreateProcessW(NULL, (char*) exeP
我正在尝试对 AWS 托管实例执行 SSH 和 SCP。我机器的公钥存储在该托管实例中。不需要 .pem 文件。我正在使用以下命令。 scp -r username@instance-id:/
所以我关注了 tutorial连接到我的远程服务器上运行的 jupyter 笔记本,以便我可以在本地 Windows 机器上访问它。 这些是我遵循的步骤。 在我的远程服务器上: jupyter not
我是一名优秀的程序员,十分优秀!