I'm having trouble with calling a system command from Java. I've tried the following:

```
if (!found) {
    dbContents += ";" + getPreviousValue(i, dbContents);

    try {
        String cmd = "echo \"Device " + headers[i] + " no data incoming at " + timeString + "\" >> /home/envir/11/log.txt";
        Runtime.getRuntime().exec(cmd);
        Console.out("N");
    }
    catch(IOException ioe) {
        System.out.println(ioe);
}

```

The thing is that the file "log.txt" is never created whatsoever. I've checked whether the if clause is ever executed or not, and i can see that the message

```
Console.out("N");

```

DOES appear, so i don't know why the 2 previous lines of code don't.

Here is the evidence that the "N" is printed:
![enter image description here](https://i.stack.imgur.com/kX7zA.jpg) 

I must say that this is the first time I use this stuff of calling a system command from a java file, so maybe this can more than probably be a newbie error.

I'd really appreciate if anyone has an answer for this.

Thanks in advance.
['https://Stackoverflow.com/questions/12280600', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1452989/']
It is likely your command is failing. Any error message is send to the Process.getErrorStream() which you are ignoring so you can't see it.

In your case, if all you want to do append to a log file, the best way to do this is in Java. It is faster, cleaner and more likely to work.

```
PrintWriter pw = new PrintWriter(new FileWriter("/home/envir/11/log.txt", true));
pw.println("Device " + headers[i] + " no data incoming at " + timeString);
pw.close();

```

The problem could be that "echo" is not a program on your system. If you are running a shell, it will have commands which are only available when that shell in running. 

BTW `>>` is a syntax only shells understand as well.
Maybe your file is not created because the redirection (">>") is not evaluated.
Try to wrap your call like this :

```
String cmd = "sh -c \"echo \\\"Device " + headers[i] + " no data incoming at " + timeString + "\\\" >> /home/envir/11/log.txt\"";

```

Anyway, why don't you use something like a FileWritter ?