On 2 February 2017 at 18:37, Dirk Hohndel <[email protected]> wrote: > Lubomir (and others) > > I know this used to work, but somehow it doesn't any more... > > subsurface.exe 1> dbg.txt 2>&1 > > instead this prints to stdout and dbg.txt stays completely empty. > > Any idea how I can get it to do what I want to do (i.e., collect all > output in a file)? >
the command line redirection (>) isn't working and i don't know why. i wonder if it ever worked. tried like 5 different solutions, to no avail. alternative solution / patch attached. what it does: - uses a new win32 specific command line argument --win32log - the freopen() call in windows.c::subsurface_console_init() now knows if we want to log the output to a file or to the CON (console) "device" - eventually it can both output to the console and write to a file you can apply it and use like so: cd <subsurface-path> subsurface.exe --win32log -v -v -v a file subsurface.log will be written. lubomir --
From 8706882d300402121d2e281f2fb014c823c404b5 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" <[email protected]> Date: Thu, 2 Feb 2017 21:00:51 +0200 Subject: [PATCH] Win32: add the --win32log option to log stdout and stderr to a file Adding --win32log as the first command line option on Windows will now log all stdout and stderr output to the file subsurface.log in the working directory. This change required a new argument 'bool logfile' to be added to: subsurface_console_init() which is defined in all platform files (linux.c, macos.c, etc.) Example usage: subsurface.exe --win32log -v -v -v Signed-off-by: Lubomir I. Ivanov <[email protected]> --- core/android.cpp | 4 +++- core/dive.h | 2 +- core/linux.c | 3 ++- core/macos.c | 5 +++-- core/subsurfacestartup.c | 5 ++++- core/windows.c | 9 ++++++--- subsurface-desktop-main.cpp | 12 +++++++++--- 7 files changed, 28 insertions(+), 12 deletions(-) diff --git a/core/android.cpp b/core/android.cpp index ef55f08..5eb8c59 100644 --- a/core/android.cpp +++ b/core/android.cpp @@ -187,8 +187,10 @@ int subsurface_zip_close(struct zip *zip) } /* win32 console */ -void subsurface_console_init(bool dedicated) +void subsurface_console_init(bool dedicated, bool logfile) { + (void)dedicated; + (void)logifle; /* NOP */ } diff --git a/core/dive.h b/core/dive.h index 2578850..95fb5f8 100644 --- a/core/dive.h +++ b/core/dive.h @@ -730,7 +730,7 @@ extern void *subsurface_opendir(const char *path); extern int subsurface_access(const char *path, int mode); extern struct zip *subsurface_zip_open_readonly(const char *path, int flags, int *errorp); extern int subsurface_zip_close(struct zip *zip); -extern void subsurface_console_init(bool dedicated); +extern void subsurface_console_init(bool dedicated, bool logfile); extern void subsurface_console_exit(void); extern bool subsurface_user_is_root(void); diff --git a/core/linux.c b/core/linux.c index b81f6bf..b050472 100644 --- a/core/linux.c +++ b/core/linux.c @@ -215,9 +215,10 @@ int subsurface_zip_close(struct zip *zip) } /* win32 console */ -void subsurface_console_init(bool dedicated) +void subsurface_console_init(bool dedicated, bool logfile) { (void)dedicated; + (void)logifle; /* NOP */ } diff --git a/core/macos.c b/core/macos.c index 500412c..20a575b 100644 --- a/core/macos.c +++ b/core/macos.c @@ -201,9 +201,10 @@ int subsurface_zip_close(struct zip *zip) } /* win32 console */ -void subsurface_console_init(bool dedicated) +void subsurface_console_init(bool dedicated, bool logfile) { - (void) dedicated; + (void)dedicated; + (void)logifle; /* NOP */ } diff --git a/core/subsurfacestartup.c b/core/subsurfacestartup.c index 7bff437..f240d13 100644 --- a/core/subsurfacestartup.c +++ b/core/subsurfacestartup.c @@ -187,7 +187,8 @@ static void print_help() printf("\n --survey Offer to submit a user survey"); printf("\n --user=<test> Choose configuration space for user <test>"); printf("\n --cloud-timeout=<nr> Set timeout for cloud connection (0 < timeout < 60)"); - printf("\n --win32console Create a dedicated console if needed (Windows only). Add option before everything else\n\n"); + printf("\n --win32console Create a dedicated console if needed (Windows only). Add option before everything else"); + printf("\n --win32log Write the program output to subsurface.log (Windows only). Add option before everything else\n\n"); } void parse_argument(const char *arg) @@ -245,6 +246,8 @@ void parse_argument(const char *arg) } if (strcmp(arg, "--win32console") == 0) return; + if (strcmp(arg, "--win32log") == 0) + return; /* fallthrough */ case 'p': /* ignore process serial number argument when run as native macosx app */ diff --git a/core/windows.c b/core/windows.c index 58d3bea..551cbf5 100644 --- a/core/windows.c +++ b/core/windows.c @@ -377,11 +377,12 @@ static struct { FILE *out, *err; } console_desc; -void subsurface_console_init(bool dedicated) +void subsurface_console_init(bool dedicated, bool logfile) { (void)console_desc; /* if this is a console app already, do nothing */ #ifndef WIN32_CONSOLE_APP + /* just in case of multiple calls */ memset((void *)&console_desc, 0, sizeof(console_desc)); /* the AttachConsole(..) call can be used to determine if the parent process @@ -421,9 +422,11 @@ void subsurface_console_init(bool dedicated) SetConsoleCtrlHandler(NULL, TRUE); /* disable the CTRL handler */ } + const char *location = logfile ? "subsurface.log" : "CON"; + /* redirect; on win32, CON is a reserved pipe target, like NUL */ - console_desc.out = freopen("CON", "w", stdout); - console_desc.err = freopen("CON", "w", stderr); + console_desc.out = freopen(location, "w", stdout); + console_desc.err = freopen(location, "w", stderr); if (!dedicated) puts(""); /* add an empty line */ #endif diff --git a/subsurface-desktop-main.cpp b/subsurface-desktop-main.cpp index 165d1f7..e30df68 100644 --- a/subsurface-desktop-main.cpp +++ b/subsurface-desktop-main.cpp @@ -34,9 +34,15 @@ int main(int argc, char **argv) QStringList importedFiles; QStringList arguments = QCoreApplication::arguments(); - bool dedicated_console = arguments.length() > 1 && - (arguments.at(1) == QString("--win32console")); - subsurface_console_init(dedicated_console); + bool win32_log = arguments.length() > 1 && + (arguments.at(1) == QString("--win32log")); + if (win32_log) { + subsurface_console_init(true, true); + } else { + bool dedicated_console = arguments.length() > 1 && + (arguments.at(1) == QString("--win32console")); + subsurface_console_init(dedicated_console, false); + } const char *default_directory = system_default_directory(); const char *default_filename = system_default_filename(); -- 1.7.11.msysgit.0
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
