Skip to content
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

Unable to retrieve version information with command line options on Windows #44694

Closed
jfbourdon opened this issue Aug 14, 2021 · 5 comments
Closed
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Windows Related to Windows operating system

Comments

@jfbourdon
Copy link
Contributor

jfbourdon commented Aug 14, 2021

What is the bug or the crash?

I'm unable to retrieve version information with command line option --version even though the option exists. Nothing is printed. Other commands like --help (image below that display what --version should do), --profile or --profiles-path work as intended.

QGIS_options

Steps to reproduce the issue

Call qgis-ltr-bin --version or qgis-bin --version and see that nothing is printed.

Versions

QGIS 3.20.0 and QGIS 3.16.9, both via OSGeo4W install
Windows 10 Version 1809

@jfbourdon jfbourdon added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Aug 14, 2021
@gioman gioman added the Windows Related to Windows operating system label Aug 14, 2021
@gioman gioman changed the title Unable to retreive version information with command line options Unable to retreive version information with command line options on Windows Aug 14, 2021
@gioman
Copy link
Contributor

gioman commented Aug 14, 2021

Also it should print that infos in the terminal/console, and not open that dialog, I think.

@agiudiceandrea
Copy link
Contributor

agiudiceandrea commented Aug 14, 2021

I'm unable to retrieve version information with command line option --version

It's an issue that occurs on Windows platforms. Also reported in #37465 (comment).

Also it should print that infos in the terminal/console, and not open that dialog, I think.

It seems this is by design, introduced with bd23bf1 and f61c993 probably just to workaround the same issue that occurs with "--version".

QGIS/src/app/main.cpp

Lines 180 to 187 in 3e28304

#ifdef Q_OS_WIN
MessageBox( nullptr,
msg.join( QString() ).toLocal8Bit().constData(),
"QGIS command line options",
MB_OK );
#else
std::cout << msg.join( QString() ).toLocal8Bit().constData();
#endif

@jfbourdon
Copy link
Contributor Author

Also it should print that infos in the terminal/console, and not open that dialog, I think.

Sorry for the confusion, I now edited my description to make it clear that --help works but not --version.

The argument --version or -v should be read...

QGIS/src/app/main.cpp

Lines 641 to 645 in f14ddac

else if ( arg == QLatin1String( "--version" ) || arg == QLatin1String( "-v" ) )
{
version();
return EXIT_SUCCESS;
}

Is it that version() function doesn't produce a valid string on Windows?

QGIS/src/app/main.cpp

Lines 121 to 125 in f14ddac

void version( )
{
const QString msg = QStringLiteral( "QGIS %1 '%2' (%3)\n" ).arg( VERSION ).arg( RELEASE_NAME ).arg( QGSVERSION );
std::cout << msg.toStdString();
}

Elsewhere strings seem to be printed with msg.toLocal8Bit().constData(); instead of msg.toStdString(); . I must say that I don't know much about C++.

@agiudiceandrea
Copy link
Contributor

agiudiceandrea commented Aug 14, 2021

Is it that version() function doesn't produce a valid string on Windows?

AFAIK the issue is due to the fact that, normally, std::cout cannot display the text string in the console when a WIN32 GUI application is executed in the CLI.
In fact, you can redirect the output of qgis-bin --version to a file using qgis-bin --version > version.txt and see a valid version text string successfully written in the file.

I now edited my description to make it clear that --help works

Do you mean it's OK for you that the --version output would be displayed in a MessageBox window like for the --help output?
In this case it should be simple to fix the issue.

EDIT: it seems it is also by design that a MessageBox window is not used for the --version output. See #30198 and in particular #30198 (review)

@jfbourdon
Copy link
Contributor Author

jfbourdon commented Aug 15, 2021

Do you mean it's OK for you that the --version output would be displayed in a MessageBox window like for the --help output?

No, I was just trying to say that all arguments were doing what we are expecting them to do. Maybe I should have remove my last sentence altogether.

Thanks for the trick qgis-bin --version > version.txt, I didn't thought about trying that. For my intended usage, it will do the job just fine.

@jef-n jef-n changed the title Unable to retreive version information with command line options on Windows Unable to retrieve version information with command line options on Windows Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Windows Related to Windows operating system
Projects
None yet
Development

No branches or pull requests

3 participants