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!";
}
Anonymous Penguin
  • 2,027
  • 4
  • 34
  • 49
  • Close voters: why is this off topic but this on topic? Both are about executing code: http://stackoverflow.com/questions/817060/creating-executable-files-in-linux – Anonymous Penguin Dec 27 '14 at 01: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. – Captain Obvlious Dec 27 '14 at 01: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`. – Keith Thompson Dec 27 '14 at 01:36
  • @CaptainObvlious some other related ones: http://stackoverflow.com/questions/15080835/running-an-executable-in-mac-terminal http://stackoverflow.com/questions/10467031/at-command-is-not-executed http://stackoverflow.com/questions/9812145/linux-how-to-execute-an-executable-non-executable-file http://stackoverflow.com/questions/14625580/difference-between-executable-and-executable and they aren't closed. – Anonymous Penguin Dec 27 '14 at 01: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. – Jonathan Leffler Dec 27 '14 at 05:36
  • Why are you running `g++` with `sudo`? – Rufflewind Dec 27 '14 at 07:57
  • @JonathanLeffler AFAIK buffers are flushed when the process dies. – edmz Dec 27 '14 at 11:14
  • g++ already makes the executable executable: You don't need chmod. Anyways, can you check stdout is open? Does checking the stream state reveal something? – edmz Dec 27 '14 at 11:15

1 Answers1

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".

23ars
  • 647
  • 3
  • 16
  • 37