bitcrazed / paws Goto Github PK
View Code? Open in Web Editor NEWTool to run a specified executable and then pause before terminating
License: MIT License
Tool to run a specified executable and then pause before terminating
License: MIT License
Nice little exercise but it has various issues.
Line 13 in c9877d2
Line 16 in c9877d2
Line 21 in c9877d2
Lines 47 to 53 in c9877d2
argv[0]
with the length of the first token in the command line. Surrounding quotes are removed in the argv elements. So, you will have different lengths if you call the program quoted or unquoted. Think about rolling your own parser to skip the first token. It's pretty straightforward. (See the next sub-issue.)
Line 61 in c9877d2
CreateProcessW
will alter the string as the documentation states.GetCommandLineW
is mutable as CreateProcessW
requires it. E.g.:
LPWSTR GetCmdLnSkipFirstToken()
{
static LPWSTR cmdLn{};
bool isInQuotes{};
bool isInToken{};
DWORD tokensCnt{};
if (cmdLn == nullptr)
cmdLn = GetCommandLineW();
for (LPWCH cursor{ cmdLn }; *cursor != L'\0'; ++cursor)
{
switch (*cursor)
{
case L' ': case L'\t': // Token separators, unless in a quoted substring
if (isInQuotes == false)
isInToken = false;
break;
case L'\"':
isInQuotes = !isInQuotes;
default: // This includes quotation marks
if (isInToken == false)
{
++tokensCnt;
if (tokensCnt > 1) // That is, the cursor points to the beginning of the second token
return cursor;
isInToken = true;
}
break;
}
}
return nullptr;
}
Further advantages:
main()
rather than wmain()
to eliminate compiler dependencies because you don't need argc
and argv
anymore. Just call your DisplayUsage
if nullptr was returned by the above functionLines 72 to 73 in c9877d2
WaitForSingleObject
here.
Line 76 in c9877d2
wcerr
stream.
Line 82 in c9877d2
CreateProcessW
failed.
Line 89 in c9877d2
static_cast<void>(_getwch());
Line 115 in c9877d2
FORMAT_MESSAGE_FROM_SYSTEM
. Nevertheless you have to pass the address of the pointer variable here.reinterpret_cast<LPWSTR>(&lpMsgBuf),
Line 118 in c9877d2
FormatMessageW
was successful you may cause undefined behavior here if you pass a null pointer to the constructor of the string.
Lines 125 to 135 in c9877d2
bool EnableVTProcessing()
{
DWORD consoleMode{};
HANDLE hConsole = { GetStdHandle(STD_OUTPUT_HANDLE) };
return (GetConsoleMode(hConsole, &consoleMode) != FALSE &&
SetConsoleMode(hConsole, consoleMode | ENABLE_VIRTUAL_TERMINAL_PROCESSING) != FALSE);
}
A couple of ANSI string literals are used for the output to the wcout stream.
Best regards
Steffen
In function clear() of struct VTColors the string.empty() calls tests whether string is empty but does not clear the string, I think you want to call string.clear() instead.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.