0

I am trying to perform a write() to stdout in Linux using a program in C.

The problem I have encountered is that this is possible before the execlp() function, but after I try to display a file in hex format with execlp() this is somehow interefering with the output making it impoissible to write anything.

Here is the code I am using:

int main(int argc, const char* const argv[])
{
    if(write(1, "OKAY", sizeof("OKAY")) == -1)
    {
        errx(1, "NOT OKAAY");
    }

    if(execlp("hexdump", "hexdump", "-v", "-e" , "/1 \"%04X\n\"", argv[1], (char*) NULL) == -1)
    {
        errx(1, "Unsuccessfull execlp");
    }

    if(write(1, "OKAY", sizeof("OKAY")) == -1)
    {
        errx(1, "NOT OKAAY");
    }

So, the first write is working correctly, then the execlp has proper output as well, and here comes the trouble with displaying the second write.

Thank you!

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
Victoria
  • 159
  • 2
  • 2
  • 13
  • 1
    Why did you tag this C++ if you are looking for a C solution? They are *quite* different languages. I took the liberty of removing the C++ tag. – Jesper Juhl Jun 07 '19 at 19:11
  • Are you sure you want to write all those null bytes after each string? – Tom Karzes Jun 07 '19 at 19:15
  • 1
    What is it that you think the exec family of functions do? They *replace* the current process with the target. As such they never return control to code that invoked them. They are typically used after calling fork. See https://linux.die.net/man/3/execlp – Dunes Jun 07 '19 at 19:23

0 Answers0