Skip to content

Instantly share code, notes, and snippets.

@Hamayama
Created October 18, 2023 12:36
Show Gist options
  • Save Hamayama/d0658e363bccda68af4b803ce4bbd529 to your computer and use it in GitHub Desktop.
Save Hamayama/d0658e363bccda68af4b803ce4bbd529 to your computer and use it in GitHub Desktop.
Windows の _execvp() の実行サンプル
@set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\local\bin;C:\msys64\usr\bin;C:\msys64\bin;%PATH%
set MSYSTEM=MINGW64
for %%i in (
inout execvp
) do (
gcc -g -O2 -Wall -Wextra -o %%i.exe %%i.c
)
pause
@set PATH=C:\msys64\mingw64\bin;C:\msys64\usr\local\bin;C:\msys64\usr\bin;C:\msys64\bin;%PATH%
@set MSYSTEM=MINGW64
@rem gdb execvp.exe
@rem execvp.exe < txtdata_in.txt > txtdata_out1.txt
@rem execvp.exe < txtdata_in.txt > txtdata_out2.txt
cat txtdata_in.txt | execvp.exe > txtdata_out1.txt
cat txtdata_in.txt | execvp.exe > txtdata_out2.txt
@rem cat txtdata_in.txt | execvp.exe | cat
@rem cat txtdata_in.txt | execvp.exe | cat
@rem inout.exe < txtdata_in.txt > txtdata_out.txt
echo ret=%errorlevel%
pause
//#include <stdio.h>
#include <process.h>
#include <unistd.h>
int main(void) {
const char* args[] = {"inout.exe", NULL};
_execvp("inout.exe", args);
sleep(30);
return 2;
}
//#include <stdio.h>
#include <io.h>
#include <unistd.h>
int main(void) {
char buf[10];
_read(STDIN_FILENO, buf, 1);
sleep(10);
_write(STDOUT_FILENO, buf, 1);
return 4;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment