Using Launchd with Mavericks and Ruby

Updated to Mavericks, and now launchd / Lingon cannot run Ruby scripts. I have files that must be executable (using chmod + x) and have the first lines set to

#!/usr/bin/ruby 

However, I keep getting the following error in the console:

 com.apple.launchd.peruser.501[169] (craig.logging[754]): Exited with code: 1 

This is a permissions error, but I have no idea which permissions to fix or change. The script works fine in the terminal with ruby.

It drives me crazy.

Update : Ruby scripts that cause the problem write their output to another file, for example, in my Dropbox. But I run the startup files as myself, who has administrator rights to write to these files. I don’t know what will go wrong ...]

Update 2 . I started using Applescript to launch the terminal and run my scripts, but it's rather clumsy and inelegant. Does anyone else have an understanding of why launchddd does not run scripts that write their output to files? Or is someone successful with scripts that do?

Update 3 . Errors were triggered due to encoding problems. I had to specifically set file.open (path / to / file, encoding: "UTF-8") for the scripts to work.

Thanks to everyone.

+6
source share
2 answers

I had the same problem in a Mavericks box with several Ruby scripts that I ran at different intervals. I found that although this machine, which had an updated OS, was failing, my new MacBook Pro, shipped with Mavericks, could schedule the same scripts with launchd just fine. I ended up washing the car and reinstalling Mavericks (and everything else) from scratch, and then I planned to run the scripts.

Not the most subtle answer, I know, but working for me.

+1
source

I'm still not quite sure why, but permission errors were triggered due to encoding issues. I had to do it specifically:

 File.open(path/to/file, encoding: 'UTF-8') 

for scripting.

Thank you all for your help.

+1
source

Source: https://habr.com/ru/post/956757/


All Articles