GnuCash
Contact   Instructions
Bug 797791 - [Windows] list of command line options after 'gnucash.exe --help'?
Summary: [Windows] list of command line options after 'gnucash.exe --help'?
Status: RESOLVED FIXED
Alias: None
Product: GnuCash
Classification: Unclassified
Component: Windows (show other bugs)
Version: 3.904
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: windows
QA Contact: windows
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-08 12:08 EDT by Jannick
Modified: 2020-06-12 03:24 EDT (History)
4 users (show)

See Also:


Attachments

Description Jannick 2020-06-08 12:08:50 EDT
gnucash-3.904-2020-06-08-git-3.904-1-gb5aeca94b+.setup.exe (Windows10):

Is there a way on the command line to retrieve GC's command line flags which become richer in these days (cf. Changelog of v 3.904)?

Suggestions after a quick google research:
- gnucash --help-all (https://wiki.gnucash.org/wiki/Logging#Command_Line_Options)
- gnucash --help (http://gnucash.1415818.n4.nabble.com/Command-line-options-td4668103.html)

But neither of them works, gnucash.exe even returns 0.  

So open cmd shell:

cd "C:\Program Files (x86)\gnucash\bin"
gnucash.exe --help
echo %ERRORLEVEL%
> 0
gnucash.exe --help-all 
echo %ERRORLEVEL%
> 0

I would love to get a help screen with the most important options after saying 'gnucash.exe --help' (provided that the GC bin folder is in PATH).  Or is this too far off? ;)


Many thanks,
J.
Comment 1 Geert Janssens 2020-06-10 16:29:53 EDT
On Windows stdout and stderr are not attached for non-console applications, hence there's no output by default.

However I learned today you can redirect the output if run from cmd (not from powershell, or at least I have not found yet how).

To do so, open the cmd.exe application and run gnucash as follows (provided the GC bin folder is in PATH):

gnucash.exe --help > outputfile.txt

outputfile.txt will then hold the captured output. Obviously the path to outputfile.txt should be writeable by the user.

To capture stderr as well, you can use
2> errorfile.txt

And you can even capture both in one go by adding both redirection symbols:
> outputfile.txt 2>&1

The latter is a special syntax for "redirect everything on stderr to wherever stdout is redirecting".

This info comes from
https://stackoverflow.com/questions/1420965/redirect-windows-cmd-stdout-and-stderr-to-a-single-file#1420981
and
https://stackoverflow.com/questions/21646641/where-does-printf-writes-in-a-windows-non-console-application



Having said that, I do think we should change our code so the command line version of gnucash (gnucash-cli) does properly output stdout and stderr.

I see there's already some basic code for this in the sources. I can probably leverage this to do what you want. Just need to get my Windows build system up and running again.
Comment 2 Geert Janssens 2020-06-11 06:44:36 EDT
The next nightly build and beta release will have a gnucash-cli that properly outputs to the console.

For gnucash itself this can't be done equally elegantly.

Under windows and application is either a Windows (ie GUI) application or a console application. It can't be both. If we make gnucash a console application it can't have windows, menus, buttons and so on. If we make it a Windows application it won't output to console.

There is a workaround to attach a console (programmatically) to a GUI application. However that would then be an extra window that opens with a black screen. For gnucash that would be distracting and annoying for the more common use case of the application so it can't be enabled by default.

I considered making a command line option just to enable a console. However by the time command line options are parsed most potentially useful output has already been processed. In addition the attached console closes with the application. So if you would enable it just to print help that help message would only flash on your screen.

So while occasionally having the gnucash console output available can be useful I think just using the redirections as described in comment 1 should be a reasonable workaround.

In that context I think it doesn't make much sense to invest more time in trying to elegantly show command line options to gnucash itself on the console.
Comment 3 Jannick 2020-06-11 15:05:48 EDT
(In reply to Geert Janssens from comment #2)
> The next nightly build and beta release will have a gnucash-cli that
> properly outputs to the console.
Great - many thanks! I'll check it out. 
> For gnucash itself this can't be done equally elegantly.
[...]
> So while occasionally having the gnucash console output available can be
> useful I think just using the redirections as described in comment 1 should
> be a reasonable workaround.
Alternative workaround without an intermediate file (just added here: https://wiki.gnucash.org/wiki/Logging#Command_Line_Options):

gnucash --help | more

Many thanks again for looking into this, Geert.
J.
Comment 4 Geert Janssens 2020-06-12 03:24:11 EDT
Clever trick to pipe it into more. I presume by default that only captures stdout. Some errors may go to stderr so perhaps you could still add 2>&1 to capture these as well. But I don't know an example offhand to test this.

Note You need to log in before you can comment on or make changes to this bug.