Author Topic: Major problem with redirecting console output to text file.  (Read 8691 times)

Offline ben321

  • Full Member
  • **
  • Posts: 182
Major problem with redirecting console output to text file.
« on: October 17, 2015, 08:52:17 PM »
I'm writing a GUI for NASM using Visual Basic. It works by when I click the "compile" button it writes a batch file that performs all the needed steps to both assemble and link the EXE file, and then issues the DEL command to delete the batch file. Because I'm trying to avoid calling up any console windows, I'm using the > operator in the batch file (so I can read any output later if needed). When used in the commandline console for Windows (which emulates a dos screen), or when using a batch (*.bat) file, the > operator is supposed to redirect any text that normally appears in the console to an output file, which is specified immediately after the > operator. So for example, if I run this command "nasm.exe /f win32 myprog.asm>nasm_log.txt" it is supposed to redirect any console output (such as errors, progress messages, etc) to the file "nasm_log.txt". But it doesn't work. I don't know how, but NASM was apparently programmed in such a way that its console output avoids being redirected to a file with the > operator, which causes the text to still appear in the console, and the resulting text file from the > operator ends up being an empty file. If this is intentional, this is extremely horrible programming practice. Console output should ALWAYS be redirectable with the > operator. If this is simply a bug, it is a bug that requires IMMEDIATE attention. I seriously hope that the NASM development team reads these forums, and learns about bugs that need fixing via reading these forums.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Major problem with redirecting console output to text file.
« Reply #1 on: October 17, 2015, 09:55:12 PM »
Nasm developers' list is here: https://lists.sourceforge.net/lists/listinfo/nasm-devel/

I'm sure they're anxious to be educated by you.

Sincerely,
Frank

P.S. Before you make too big a fool of yourself, you might want to look into the "-z" or "-s" options... http://www.nasm.us/doc/nasmdoc2.html#section-2.1.14


Offline ben321

  • Full Member
  • **
  • Posts: 182
Re: Major problem with redirecting console output to text file.
« Reply #2 on: October 18, 2015, 05:13:36 AM »
Nasm developers' list is here: https://lists.sourceforge.net/lists/listinfo/nasm-devel/

I'm sure they're anxious to be educated by you.

Sincerely,
Frank

P.S. Before you make too big a fool of yourself, you might want to look into the "-z" or "-s" options... http://www.nasm.us/doc/nasmdoc2.html#section-2.1.14

Thanks for the info. I also found another workaround. You can make the > operator dump the content of the stderr stream to a file by using a 2 before the > operator, like this:
someprog.exe 2>textfile.txt

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Major problem with redirecting console output to text file.
« Reply #3 on: October 18, 2015, 11:43:12 AM »
Really? Cool! I know 2> redirects stderr in a "real" OS, but Dos didn't used to do it. There was a way to do it (involved "dup", I think) but I don't remember what it was. (lots of memory gone south) If it works in Windows, you're all set.

Best,
Frank


Offline ben321

  • Full Member
  • **
  • Posts: 182
Re: Major problem with redirecting console output to text file.
« Reply #4 on: October 18, 2015, 07:58:50 PM »
Really? Cool! I know 2> redirects stderr in a "real" OS, but Dos didn't used to do it. There was a way to do it (involved "dup", I think) but I don't remember what it was. (lots of memory gone south) If it works in Windows, you're all set.

Best,
Frank

Works in the Windows console (at least on Win7, not sure about WinXP). Windows console you get to with cmd.exe, and even though it looks like dos, it's just a console-based interface for Windows. So you are probably right that this isn't a DOS function. It's a Windows function, accessible only through the console.

Offline call [Lawrence]

  • New Member
  • Posts: 1
Re: Major problem with redirecting console output to text file.
« Reply #5 on: March 31, 2016, 04:24:02 PM »
Below is redirection under generic Windows.

There are also extensions to the windows command-line. As of XP, I believe they're enabled by default.

There is also PowerShell (an OS unto itself).

command >file
Write standard output of command to file

command 1>file
Write standard output of command to file (same as previous)

command 2>file
Write standard error of command to file (OS/2 and NT)

command >file 2>&1
Write both standard output and standard error of command to file (OS/2 and NT)

command >>file
Append standard output of command to file

command 1>>file
Append standard output of command to file (same as previous)

command 2>>file
Append standard error of command to file (OS/2 and NT)

command >>file 2>&1
Append both standard output and standard error of command to file (OS/2 and NT)

commandA | commandB
Redirect standard output of commandA to standard input of commandB

commandA 2>&1 | commandB
Redirect standard output and standard error of commandA to standard input of commandB (OS/2 and NT)

command < file
command gets standard input from file

command   2>&1
command's standard error is redirected to standard output (OS/2 and NT)

command 1>&2
command's standard output is redirected to standard error (OS/2 and NT)

L