Skip to content

Instantly share code, notes, and snippets.

@binki
Created February 19, 2018 01:15
Show Gist options
  • Save binki/d8be8a7eb90340d660582e0ba8caf08a to your computer and use it in GitHub Desktop.
Save binki/d8be8a7eb90340d660582e0ba8caf08a to your computer and use it in GitHub Desktop.
Windows command line
#include <windows.h>
int main(
int argc,
const char *const argv[]) {
const HANDLE stdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
if (stdOutput == INVALID_HANDLE_VALUE) {
return 1;
}
const LPSTR cmdLine = GetCommandLine();
if (!WriteFile(stdOutput, cmdLine, lstrlenA(cmdLine), NULL, NULL)) {
return 1;
}
const char *nl = "\r\n";
if (!WriteFile(stdOutput, nl, lstrlenA(nl), NULL, NULL)) {
return 1;
}
return 0;
}
C:\Users\ohnob\repos\winmain-play>.\main This is a string that isn't quoted or anything
.\main This is a string that isn't quoted or anything
C:\Users\ohnob\repos\winmain-play>.\main "this is a string quoted ""using conventions"""
.\main "this is a string quoted ""using conventions"""
C:\Users\ohnob\repos\winmain-play>.\main --blah='asdflkj'
.\main --blah='asdflkj'
C:\Users\ohnob\repos\winmain-play>.\main --blah="asdflkj"
.\main --blah="asdflkj"
C:\Users\ohnob\repos\winmain-play>.\main "--blah="asdflkj"
.\main "--blah="asdflkj"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment