6 comments

  • theamk1 day ago
    Raymond&#x27;s posts are always fun to read, but it sometimes he focuses more on the &quot;proper&quot; methods, and does not even acknowledge that there are hacky workarounds.<p>Like for this case - sure, you cannot redefine the standard output handle, but that&#x27;s not what the customer asked for, is it? They said &quot;read&quot; and I can see a whole bunch of ways to do so - ReadConsoleOutput + heuristic for scrolling, code inject into console host, attach debugger, set up detour on logging function, custom kernel module...<p>To be fair, as a MS support person, it&#x27;s the exactly right thing to do. You don&#x27;t want the person to start writing custom kernel module when they should redirect stdout on process start instead. But as a random internet reader, I&#x27;d love to read all about hacky ways to achieve the same!
    • bigstrat20031 day ago
      &gt; Raymond&#x27;s posts are always fun to read, but it sometimes he focuses more on the &quot;proper&quot; methods, and does not even acknowledge that there are hacky workarounds.<p>Nor should he, IMO. Hacky workarounds are almost always a terrible idea that will bite you in the ass someday.
      • integralid1 day ago
        As a hacker, I&#x27;m sorry, reverse engineer hacky workarounds is what I do. When I want to read stdout of a malware process I&#x27;m not going to ask a developer nicely, in going to grab my trusty debugger or API monitor.<p>But yeah, <i>for production quality software</i> hacks are the very last resort. It&#x27;s still fun and enlightening to know them, though.
      • yndoendo1 day ago
        Had a WPF touch interface application that would latch on when a person; presses, holds, and slides their finger off the screen. Highly unacceptable when it controls a machine that could remove a limb.<p>Only fix was to write a custom touch screen event handler that overrides the built in one by Microsoft.<p>I would love to have a _proper method_ and pull out my _hacky_ method that prevents the removal of a person&#x27;s limb.
      • AmazingTurtle1 day ago
        Hacky workarounds aren&#x27;t rare exceptions; they&#x27;re the plumbing of modern software. Anti-cheat and antivirus tools only work because they lean on strange kernel behaviors. Cloud platforms ship fixes that rely on undefined-but-stable quirks. Hardware drivers poke at the system in ways no official API ever planned for.<p>Yeah, they&#x27;re ugly, but in practice the choice isn&#x27;t between clean and hacky; it&#x27;s between shipping and not shipping. Real-world software runs on constraints, not ideals.
        • tetha1 day ago
          On the other hand, everything you ship outside of a clearly established golden path is a maintenance burden that piles and piles and piles. And these maintenance burdens tend to gradually slow the org down until they cause rather catastrophic failures, usually out of security or hardware (read: fire) incidents. Or HR reasons because people figure there are better places to fight fires.
  • ranger_danger1 day ago
    I know this article is for Windows, but if you&#x27;re wondering if there&#x27;s a way to do this on Linux, there is:<p><a href="https:&#x2F;&#x2F;strace.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;strace.io&#x2F;</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;nelhage&#x2F;reptyr" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;nelhage&#x2F;reptyr</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;crigler&#x2F;dtach" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;crigler&#x2F;dtach</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;jerome-pouiller&#x2F;reredirect" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jerome-pouiller&#x2F;reredirect</a><p><a href="https:&#x2F;&#x2F;github.com&#x2F;pasky&#x2F;retty" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;pasky&#x2F;retty</a>
    • zaius1 day ago
      Here&#x27;s my method using GDB from many years ago: <a href="https:&#x2F;&#x2F;gist.github.com&#x2F;zaius&#x2F;782263" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;zaius&#x2F;782263</a>
    • maxjohan1 day ago
      Is there a way to read from present tty?<p>In practice: I boot into tty and manually start the graphical session (Wayland&#x2F;Sway). I occasionally get (non-Sway) warnings when I return to tty (eg close the window manager). But the output is always scuffed, so I can&#x27;t read the whole log. The lines get printed on top of each other or something.<p>Is there a way to read everything from tty, from within the tty?<p>Neither of the methods below work, because the warnings&#x2F;errors aren&#x27;t produced by Sway itself, but some other OS module&#x2F;component.<p>$ sway |&amp; tee &#x2F;tmp&#x2F;sway.log<p>$ tail -f &#x2F;tmp&#x2F;sway.log
      • toast01 day ago
        If things are printed on top of each other, try script?<p><a href="https:&#x2F;&#x2F;man.freebsd.org&#x2F;cgi&#x2F;man.cgi?query=script&amp;apropos=0&amp;sektion=1&amp;manpath=FreeBSD+15.0-RELEASE+and+Ports&amp;arch=default&amp;format=html" rel="nofollow">https:&#x2F;&#x2F;man.freebsd.org&#x2F;cgi&#x2F;man.cgi?query=script&amp;apropos=0&amp;s...</a><p>But, if you&#x27;re getting console debugs from the kernel, that wouldn&#x27;t be captured either... Otoh, debug output from the kernel should also go into logs or dmesg or something?<p>You&#x27;ll capture <i>everything</i> and maybe be able to figure it out from there?
        • maxjohan1 day ago
          Thanks for the input! Sounds promising. I&#x27;ve to admit, &#x27;script&#x27; doesn&#x27;t say anything to me yet. I&#x27;ve to look into it.<p>About the logs, yes, I have yet to dive into that. The _everything_ part makes it very tedious, so I had hoped for another solution :)
          • ranger_danger1 day ago
            If script doesn&#x27;t work, you could maybe try starting everything from within GNU screen or tmux with logging turned on?
            • maxjohan19 hours ago
              These methods would fetch Sway error messages, but nothing else, no? This is not about Sway messages.
          • toast01 day ago
            oh, one more thing... your pipeline is only capturing stdout; errors often get logged to stderr ... script (or screen&#x2F;tmux logging) will capture both though.
            • maxjohan19 hours ago
              Thanks for the notice! Embarrassing rookie mistake ;)
      • yjftsjthsd-h1 day ago
        It might be useful to try and figure out what&#x27;s logging the messages.<p>However, if it was me, I&#x27;d strongly consider just starting from your shell in the tty, then running tmux, then starting sway, then attaching to tmux from a terminal emulator.
        • maxjohan1 day ago
          Thanks for your reply! I&#x27;ve thought about that as well. Haven&#x27;t tried it though. Two thoughts about it:<p>1. Running graphical from within tmux feels unsafe (?). Introducing another layer can&#x27;t be the way to go. BUT this comes from a position of limited knowledge, so I might stand corrected on this one. Also, doing it once for debugging won&#x27;t do any harm.<p>2. I&#x27;m pretty sure the errors are not printed by Sway itself, but some other OS module. Errors that Sway cause for other modules won&#x27;t be included in the Sway log. So the problem remains, no?
    • baobun1 day ago
      This prompted me to ask the crowd about a similar use-case of editing your command line as it&#x27;s already running your command<p><a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=46234678">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=46234678</a>
    • mzs1 day ago
      vxworks 6.x:<p>(one login session, say over serial)<p><pre><code> -&gt; ioTaskStdGet 0, 1 value = 3 = 0x3 -&gt; taskIdSelf value = 13600784 = 0xcf8810 </code></pre> (another session, say over telnet)<p><pre><code> -&gt; ioTaskStdSet 0xcf8810, 1, 0x9 value = 0 = 0x0 </code></pre> (first session ie SERIAL)<p><pre><code> -&gt; printf &quot;foo\n&quot; -&gt; taskIdSelf -&gt; i </code></pre> (otherone eg TELNET)<p><pre><code> -&gt; foo value = 4 = 0x4 value = 13600784 = 0xcf8810 NAME ENTRY TID PRI STATUS PC SP ERRNO DELAY ---------- ------------ -------- --- ---------- -------- -------- ------- ----- ... </code></pre> teeheeheehaw!
    • glhaynes1 day ago
      I assume roughly the same caveats would apply, though? Buffering might be set wrong (and have no mechanism to be updated because the program never checks again), etc.
    • jmclnx1 day ago
      Thanks, links saved.<p>Then there is this method, but I guess that article refers to no redirection output.<p>If in background or via cron, I always redirect. But this is for UN*X type systems with a tail that supports &#x27;-f&#x27;<p>$ prog &gt; &#x2F;tmp&#x2F;log.txt 2&gt;&amp;1 &amp;<p>Then<p>$ tail -f &#x2F;tmp&#x2F;log.txt<p>Just so happens, I actually used this the other day for a long running process on OpenBSD :)
      • smcameron1 day ago
        Can&#x27;t you just read from &#x2F;proc&#x2F;pid&#x2F;fd&#x2F;0 ?
        • irishcoffee1 day ago
          This was my first thought as well. I assume somehow I&#x27;m the dummy that doesn&#x27;t understand the question.
        • jmclnx11 hours ago
          OpenBSD does not have a &#x2F;proc file system.
      • hmng1 day ago
        Isn&#x27;t that what tee is for? Like<p>$ prog | tee &#x2F;tmp&#x2F;log.txt
        • jmclnx1 day ago
          When I submit a process to bg, I mostly use cron and I do not care about seeing output during runtime.<p>So, tail suites my needs in the rare cases something unexpected seems to be happening.
        • gosub1001 day ago
          That&#x27;s if you start the process with advance knowledge that you&#x27;ll want to tail the output and log it. Not if you want to view the output of an existing process
          • hmng1 day ago
            Yes, but I was replying to the above, using redirection and tail -f.
  • amelius1 day ago
    Can&#x27;t you attach to it from GDB?
    • gary_01 day ago
      Or you could patch the executable on disk or in memory, or probably some other hacks I&#x27;m not thinking of. I think he means that there&#x27;s no Windows API or &quot;proper&quot; way to do it, not that it&#x27;s literally impossible (it&#x27;s running on a general-purpose computer, after all).
  • jeffrallen1 day ago
    strace (8).
  • bh0k4l1 day ago
    How I use the script command to read the output of the last command and ask an LLM for help:<p>The following custom command is executed for starting the terminal<p><pre><code> &#x2F;usr&#x2F;bin&#x2F;zsh -c &#x27;export SCRIPT_LOG_FILE_NAME=$(date &quot;+%m-%d-%y-%H-%M-%S-%N&quot;) &amp;&amp; mkdir -p &#x2F;tmp&#x2F;script-log&#x2F; &amp;&amp; script -f -q &#x2F;tmp&#x2F;script-log&#x2F;$SCRIPT_LOG_FILE_NAME&#x27; export SCRIPT_LOG_FILE_NAME=$(date &quot;+%m-%d-%y-%H-%M-%S-%N&quot;) mkdir -p &#x2F;tmp&#x2F;script-log&#x2F; script -f -q &#x2F;tmp&#x2F;script-log&#x2F;$SCRIPT_LOG_FILE_NAME </code></pre> The date sub-command creates a unique filename for the current session and stores it in SCRIPT_LOG_FILE_NAME.<p><pre><code> export SCRIPT_LOG_FILE_NAME=$(date &quot;+%m-%d-%y-%H-%M-%S-%N&quot;) </code></pre> Create a folder in &#x2F;tmp&#x2F;script-log&#x2F;.<p><pre><code> mkdir -p &#x2F;tmp&#x2F;script-log&#x2F; </code></pre> Script then writes the current terminal session to that file.<p><pre><code> script -f -q &#x2F;tmp&#x2F;script-log&#x2F;$SCRIPT_LOG_FILE_NAME </code></pre> Now any command run in this terminal knows where the last program wrote its output.<p>We can split the log at the last $PS1 prompt and feed the most recent chunk to a utility such as Simon W.&#x27;s llm.<p>Add the following to .zshrc (or …):<p><pre><code> alias z=&#x27;tail -n 100 &#x2F;tmp&#x2F;script-log&#x2F;$SCRIPT_LOG_FILE_NAME | llm -s &quot;Fix it or similar&quot; | pbcopy&#x27; </code></pre> Essentially, run a command; if it fails, run z.
    • bmacho1 day ago
      On HN you can have a <i>code block</i> by adding 2 spaces before each line