Sublime Forum

Cannot start sublime under sudo

#1

I am on Mac, and I ran the command sudo su -, so I entered into root mode, and now as a root I executed a command subl file.txt. Sublime has started with a new empty file with no contents, not opening the file at all. I’ve tried opening the file with other text editors like Visual Studio Code and vim which worked fine. When I tried to quit Sublime, it instantly reopened again, and even if it lost focus, it went back again. So I quickly clicked on the console and pressed Ctrl+C to cancel the command, so I could close Sublime Text. If I did sudo subl file.txt, it would open fine, but not under the root. Is this a feature or a bug?

0 Likes

#2

Trying to open subl in su doesn’t work for me at all on Arch. Nothing happens.

subl --help does print the help message, though.

I’m inclined to believe this is a feature, but am not sure why.

0 Likes

#3

On my MacBook running MacOS 10.10.5, I executed the following:

Last login: Mon Sep 18 19:43:05 2017 from dart
tmartin:tmac:~\> sudo su -
tmac:~ root# echo "I am the contents of test.txt" > test.txt
tmac:~ root# subl test.txt

As mentioned above, this starts sublime and opens a window, but does not open the file. However, I can quit Sublime or otherwise lose focus without seeing the behaviour mentioned; it seems to work as per normal except that it doesn’t open the file at all. The same is true if Sublime is already running when I execute the command; it gives the window focus, but does not open the file.

However, the same sequence of steps on my Slackware Linux box opens the file as I would expect it to. If Sublime is already running, it starts a new copy using /root/.config/sublime-text-3 as the configuration directory. Presumably that’s because each user gets their own shared memory handle for communicating with an already running process though.

0 Likes

#4

related:



0 Likes

#5

Same here on 10.12.6. This also fails, with TextEdit starting but failing to open te file:

Koens-MacBook-Pro:~ root# open test.txt
LSOpenURLsWithRole() failed with error -10810 for the file /private/var/root/test.txt

¯_(ツ)_/¯

0 Likes