8000 Forward command line arguments for window launchers by firai · Pull Request #1572 · winpython/winpython · GitHub
[go: up one dir, main page]

Skip to content

Forward command line arguments for window launchers #1572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 8, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
More reliable way to deal with whitespace
  • Loading branch information
firai authored Apr 26, 2025
commit 4a624c67f912ad3b4bafa17cbe07342a82a2a9d0
32 changes: 16 additions & 16 deletions portable/launchers_src/launcher_template_WINDOWS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /
std::wstring exeDir = exePath;
exeDir = exeDir.substr(0, exeDir.find_last_of(L"\\/"));

// Get command line string
// Get command line string and extract arguments
LPWSTR commandLine = GetCommandLineW();
// Skip the current executable path and name
std::wstring args;
if (commandLine) {
// If path is double quoted, skip the entire double quote
if (commandLine[0] == L'"') {
LPWSTR closingQuote = wcschr(commandLine + 1, L'"');
if (closingQuote) {
args = closingQuote + 1; // Skip closing quote and space
}
// Otherwise skip to first space
} else {
LPWSTR spacePos = wcschr(commandLine, L' ');
if (spacePos) {
args = spacePos + 1; // GetCommandLineW puts 2 spaces when path isn't double quoted
}
// If executable path is double quoted, skip the entire quoted section
if (commandLine[0] == L'"') {
LPWSTR closingQuote = wcschr(commandLine + 1, L'"');
if (closingQuote) {
args = closingQuote + 1;
}
// For non-quoted path, skip to character after first space if it exists
} else {
LPWSTR spacePos = wcschr(commandLine, L' ');
if (spacePos) {
args = spacePos + 1;
}
}
// Strip leading whitespace
size_t args_start = args.find_first_not_of(L" ");
args = (args_start != std::wstring::npos) ? args.substr(args_start) : L"";

// Define the path to the "scripts" directory
std::wstring scriptsDir = exeDir + L"\\scripts";
Expand All @@ -60,7 +60,7 @@ int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR /
// Define the command to run and append arguments if present
std::wstring target;
if (!args.empty()) {
target = L"cmd.exe /c \"\"" LAUNCH_TARGET L"\"" + args + L"\"";
target = L"cmd.exe /c \"\"" LAUNCH_TARGET L"\" " + args + L"\"";
} else {
target = L"cmd.exe /c \"" LAUNCH_TARGET L"\"";
}
Expand Down
0