How to get Guard "live" output in terminal - ruby

I'm currently using Guard along with the guard-pytest plugin to run the appropriate tests when files change. I was using sniffer, but it doesn't seem to have as much control as I would like, I want to run specific tests, not all of them (and I am a long-time guard user). I am on Mac OSX.
The problem is, Guard or Ruby or Python seem to be buffering the output, so that if a test takes a while to run, I have to wait a while with no feedback in the terminal on the tests in progress. Once the tests have completed, all the output comes at once. Anyone have any experience with getting "live" output from Guard? I messed around with $stdout = sync, PYTHONUNBUFFERED=1 and various attempts at getting readline support, but here I am, asking on StackOverflow.
Any help would be appreciated.

guard-pytest doesn't work too well if the commands take time:
https://github.com/kazufusa/guard-pytest/blob/master/lib/guard/pytest.rb#L20
Basically, it collects the output, then outputs it as a whole.
I created a PR to fix this: https://github.com/kazufusa/guard-pytest/pull/2

Related

Bash Scripts (even trivial ones) stuck when invoked on the terminal

I have a server on which we execute multiple bash scripts to automate tasks (like copying files to other servers, kicking off backups, etc). It has been working for some months, but today it started to get erratic.
What is happening, is that the script gets 'stuck' for a while, and after that, it runs with no problem. If I copy and paste the commands one by one on the terminal, it works, so is not something on the script itself, but it seems something that is preventing the bash interpreter (if that makes sense).
Another weird behavior is that the same script will run with no issues eventually. However, as we use Jenkins for automation, the scripts are re-created every time a new job starts.
For example, I created a new script, tst.sh, which only contains an echo. If I try to run it directly, it gets stuck for a while. I tried to debug it with bash -xeav but it does not print my script code, which means that it is not reading it. After a while, the script ran, with no changes. However, creating one script, with the same content and a different name, resurfaces the issue.
My hypothesis is that something prevents the script to be read, and just waits until whatever is blocking it to finish. However, I did not see any process holding the file, which means that it may not the case.
Is there any other thing I should try? My knowledge in bash is pretty basic, so I don't know if there is a flag that may help me on debugging this internally.
I am working on RHEL 8.85, the bash version is GNU bash, version 4.4.20(1)-release (x86_64-redhat-linux-gnu)
UPDATES BASED ON THE COMMENTS
Server resources are OK, no usage for them.
Hardware for the server also works fine, the ops team has not reached out with any known issue at least
Reboot makes the issue disappear, however, it reappears after 5 minutes or so
The issue seems that is not related to bash profiles and such.
Issue solved, posting this as an answer so people can find it quicker.
Turns out, as multiple users suggested in the comments (thanks to all!!) the problem was caused by a security monitor, which analyzed each of the scripts that were executed. The team changed some settings on that end to prevent it from happening, and so far is working.

Livecode standalone program takes 30 seconds to load

I've run into an issue with a program I created using Livecode, and now I'm looking for some help from the experts. My Google-fu is strong, yet the answer eludes me...
So here's the deal. I made a very basic note-taking program for Windows only, using very noob skills. I've been using it daily for work for the past month at least. It functions exactly as it should, except for these few things that don't make sense:
When loading the program, it takes 25-30 seconds to load. Not convenient considering it's pretty basic; one button and 5-6 text input fields, with the same number of label fields. And one background. The button just clears the text input fields.
I started to notice a problem when I went to create a batch file to load all my work programs. When the program is loaded thru Command Prompt, if I close CMD it will close the program too. I tried the same using Powershell, and it still closes as soon as the Powershell window closes. Really really strange.
I managed to find another standalone program made with Livecode, downloaded it and tested the CMD command to see if the same thing happened. It didn't, that program loaded instantly and it is ENORMOUS. It also didn't close when I closed the CMD window. I even tried this: opened my program and the downloaded program using the same CMD session, and when I closed CMD, my program closed but the downloaded one did not.
Then, I downloaded the source code for the program that was working correctly. I created a standalone for it, and tried to open that. It acts the same way as my note program does.
I don't get it. It's got to be something in my Standalone Application Settings considering what happened in the last step I mentioned, and I've been over and over those settings for hours, but I just don't have the knowledge of LC to know what to look for. I've scoured the web looking for answers to this, but it seems to be just me having this issue (story of my life, lol).
I'll be happy to post any codes, scripts, or files needed, please let me know. I just don't know which things to post =P
Any suggestions are very much appreciated!! Thank you. =)
If you call the program from the prompt directly, e.g. using
C:\program files (x86)\your_standalone.exe
the app is treated as a command line app. I have also noticed that a LiveCode app can sometimes close if the invoking command line prompt is closed, while it may sometimes continue to run. Perhaps the handling of the relaunch message has to do with it, since this message basically handles commands from the command line.
If you want the command line process to finish independently from the invoked LiveCode application, you can use the start command:
start "" "C:\program files (x86)\your_standalone.exe"
don't have enough info to be able to tell what your issue is. But that much of a delay is not usual for LiveCode apps so something is definitely wrong. How long does your app take to load if you open the stackfile in the IDE?
Not sure what StackOverflow allows but if you could upload your scripts and if possible stackfile that will give us more to go on
This has nothing to do with Windows, Batchfiles, or CMD.
CMD can workaround your problem, if it's a GUI program. See Start command, and read the help as it explains the starting behaviour of CMD and CMD's Start.
Explorer has different rules. Anything else that starts programs call CreateProcessExW which has it's own rules.

Rspec process hangs at different places, process cannot be killed. How to diagnose?

In a rails application I'm developing (on OS-X), I'm finding running the test suite via rspec locking up increasingly frequently. It does not happen every time. I've tried adding --format documentation when running the suite to see if it happens at the same place every time, and it does not.
I've tried killing the process with kill -9. It then changes the name to (ruby) with a process status of ?E. This link suggests that the process is blocked waiting for a system call to finish. I have to restart my machine every time this happens in order to kill this process.
I've tried re-installing rvm, ruby, mysql, and imagemagick. This project is using imagemagick (via the mini_magick) gem, and I suspected that it may be one of these commands that is causing rspec to block. I tried adding puts statements around each of the mini_magick commands to ensure they finish executing, and all looks fine.
I'm looking for suggestions on how to diagnose this issue.
It's possible your problem is an order-dependency bug, you can pass the seed along and the order will remain consistent.
RSpec prints out the random number it used to seed the randomizer.
Use this number to run rspec with the same order
--order rand:3455

Ruby system call (on windows) without a popup command prompt

I am trying to tidy up a process that uses multiple system calls from inside a ruby script executed using rubyw.exe (1.8.7).
As far as I can understand the main reason for rubyw.exe is that it doesn't pop up a command prompt to distract the user. However it appears that the system calls from within that process still do generate these popups which is very distracting for the users of this process script.
Does anyone know how to do this?
There are lots of questions similar to this on SO but none which quite answers this, if I was using python this questions/answer would help (http://code.activestate.com/lists/python-list/46042/) but so far my searching hasn't found a way to accomplish this with ruby.
UPDATE: There is this thread here Hiding curl Window on Windows which is close but the only working solution there doesn't also allow you to get the standard output.
I ended up going with the win32-open3 gem. Because fork isn't implemented on windows systems you can't use the built in open3 and you'll need to do a
gem install win32-open3
However this comes with flags that you can pass to the call method, in particular
There are a couple of differences in the Windows version for open3
(which
also apply to Open4.popen4) - the mode flag and the show flag. For the
mode, you can specify either 't' (text, the default) or 'b' (binary) as a
second argument. For the show flag, you can specify either true or false,
which will show the console window, or not, depending on the value you
pass. The default is false.
Users of this particular script are no longer bombarded with 15 cmd windows that constantly steal focus, so .... win?

How to log STDOUT of a background process w/o buffering on Mac?

I am running a background process on Mac and have a problem with log update. If I run
someprog > mylog &
then mylog is updated not immediately, but with some intervals - I guess it's due to buffering. Same thing with at now. If I kill the program before output is written to mylog, then I loose the data. There was no such problem with the same program on Linux machines, so I hope I can make it run-time-updated on Mac as well. Any idea how?
someprog is a F77 program, which was not written by me.
I tried to ask this question at SuperUser, but no one can help me there.
EDIT1: I don't feel like changing the source, but keep it in mind. Logging works fine on Linux machines, so it should work on Macs as well. It must be a system setting, e.g. buffer size? It would be fine for me to limit the buffer size to a smaller value - now I have to wait hours to see something in the log.
If you have access to the source code, you can probably just add calls to fflush(stdout) after every printf. If you don't, you could try something tricky with LD_PRELOAD... Basically, make your own version of printf() that calls libc's printf... AND does a flush... Then LD_PRELOAD that library when you run... The app will use yours instead... Kinda risky tho...
That's the usual behaviour of POSIX C programs that are writing to a non-tty stream - I guess F77 shares the same behaviour, or is written in terms of the stdio routines.
I don't know what the right answer is - I guess you'll need to pipe the output through something that pretends to be a tty, but offhand I don't know what (if any) utility provides that option.

Resources