SQLite Forum

a probable bug in .output handler
Login
That balance is a challenge, particularly for these redirection commands. Below, I propose replacements for all 3 which capture their behavior and provide some clues for cases when system settings may alter that behavior. (I encountered such difficulty myself, and had to read code to discover why output to a spreadsheet did not work. I was tempted to explain that, on Windows, %COMSPEC% must expand to invoke cmd.exe before -e or -x can work as stated, but that would only benefit those running non-stock shells.)

Present help:

```
  /*--+----- --------- -----+--+ --------- --------- --------- --------- ----*/
  ".excel                   Display the output of next command in spreadsheet",
  "   --bom                   Put a UTF8 byte-order mark on intermediate file",
...
  ".once ?OPTIONS? ?FILE?   Output for the next SQL command only to FILE",
  "     If FILE begins with '|' then open as a pipe",
  "       --bom  Put a UTF8 byte-order mark at the beginning",
  "       -e     Send output to the system text editor",
  "       -x     Send output as CSV to a spreadsheet (same as \".excel\")",
...
  ".output ?FILE?           Send output to FILE or stdout if FILE is omitted",
  "   If FILE begins with '|' then open it as a pipe.",
  "   Options:",
  "     --bom                 Prefix output with a UTF8 byte-order mark",
  "     -e                    Send output to the system text editor",
  "     -x                    Send output as CSV to a spreadsheet",
```

Proposed help without functionality changes:

```
  /*--+----- --------- -----+--+ --------- --------- --------- --------- ----*/
  ".excel ?OPTION?          Next SQL output as .CSV and opened in spreadsheet",
  "   OPTION may be --bom to prefix output with a UTF8 byte-order mark.",
  "   Output is a temp-file with a .csv extension, opened by any program that",
  "   has been designated by the system for such files, often a spreadsheet.",
  /*--+----- --------- -----+--+ --------- --------- --------- --------- ----*/
  ".once ?OPTION? ?SINK?    Output for the next SQL command only goes to SINK",
  "   OPTION may be --bom to prefix output with a UTF8 byte-order mark.",
  "   If SINK begins with '|' then open it as a pipe, else it either names a"
  "   file or is one of the following to produce then process a temp-file:",
  "      -e     Output as .txt and then open in system text editor for .txt",
  "      -x     Output as .CSV then open in spreadsheet (same as \".excel\")",
  /*--+----- --------- -----+--+ --------- --------- --------- --------- ----*/
  ".output ?OPTION? ?SINK?  Output for subsequent SQL commands goes to SINK",
  "   OPTION may be --bom to prefix output with a UTF8 byte-order mark.",
  "   If SINK begins with '|' then open it as a pipe, else it either names a"
  "   file or is one of the following to produce then process a temp-file:",
  "      -e     Output as .txt and then open in system text editor for .txt",
  "      -x     Output as .CSV then open in spreadsheet (same as \".excel\")",
  "   Output is diverted until .output or .once SINK is omitted or \"stdout\"."
  /*--+----- --------- -----+--+ --------- --------- --------- --------- ----*/
```