1

I'm trying to run my application as root because I need to access low level hardware on my computer.

When I run the command:

./application_name

...it works, except gives an error that it needs root. However, when I run this:

sudo ./application_name

...I get no terminal ouput.

I've tested that every time that I run an executable on Linux as root, it doesn't print anything to terminal. How can I fix this?

Edit: somewhat of a test case provided (mobile so can't type out much):

sudo g++ test.cpp -o executable
sudo chmod +x executable

This works on Debian:

./executable

This doesn't:

sudo ./executable

test.cpp:

#include <iostream>

int main() {
  std::cout << "Hello World!";
}
8
  • Close voters: why is this off topic but this on topic? Both are about executing code: stackoverflow.com/questions/817060/… Commented Dec 27, 2014 at 1:22
  • 1
    That question is five years old and was posted at a time when the posting guidelines were quite different. The existence of a very old question does not mean it is OK to post a similar one. Commented Dec 27, 2014 at 1:36
  • 1
    Apparently that's how the application behaves. Some applications just don't produce output (/bin/true, for example). We know nothing at all about the application, so we can't help you figure out why it's not producing any output. Try sudo echo hello; it should print hello. Commented Dec 27, 2014 at 1:36
  • @CaptainObvlious some other related ones: stackoverflow.com/questions/15080835/… stackoverflow.com/questions/10467031/at-command-is-not-executed stackoverflow.com/questions/9812145/… stackoverflow.com/questions/14625580/… and they aren't closed. Commented Dec 27, 2014 at 1:50
  • 1
    Note that you don't terminate the output with a newline. Adding << endl or including a newline in the string to be printed would improve the chances of the output being printed. That doesn't really explain the difference between root and non-root behaviour. Commented Dec 27, 2014 at 5:36

1 Answer 1

1

That behavior is really strange. Root permissions for that application should have no effect on std output. For example, I made a simple test, a "hello world" that I ran as root on Debian OS and I had output in terminal.

A simple test to convince yourself that you should have the output, is to make a redirect to a file. For example sudo ./executable > output.txt and you'll see that everything should be OK.

Note that it should be strange if you don't have output from a simple "hello world".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.