Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
spelling in title
Link
Cœur
  • 39k
  • 25
  • 207
  • 282

IOexception while runingrunning bash commands through ProcessBuilder

added 22 characters in body
Source Link
Aboutblank
  • 727
  • 3
  • 14
  • 31

I am getting a IOException when trying to run a sed command through Java using a ProcessBuilder:

ERROR: java.io.IOException: Cannot run program "sed -i 's/hello world//g' /home/user/test": error=2, No such file or directory 

The command is sed -i 's/hello world//g' /home/user/test But the problem isn't the command, I can run the same command through terminal and it would remove the string "hello world"

public void removeString(String str, String file) throws IOException { String command = "sed -i \'s/" + str + "//g\' " + file; System.out.println(command); ProcessBuilder pb = new ProcessBuilder(command); Process p = pb.start(); } 

Why can'tWhat is causing the process to be unable to find the file?

I am getting a IOException when trying to run a sed command through Java using a ProcessBuilder:

ERROR: java.io.IOException: Cannot run program "sed -i 's/hello world//g' /home/user/test": error=2, No such file or directory 

The command is sed -i 's/hello world//g' /home/user/test But the problem isn't the command, I can run the same command through terminal and it would remove the string "hello world"

public void removeString(String str, String file) throws IOException { String command = "sed -i \'s/" + str + "//g\' " + file; System.out.println(command); ProcessBuilder pb = new ProcessBuilder(command); Process p = pb.start(); } 

Why can't the process find the file?

I am getting a IOException when trying to run a sed command through Java using a ProcessBuilder:

ERROR: java.io.IOException: Cannot run program "sed -i 's/hello world//g' /home/user/test": error=2, No such file or directory 

The command is sed -i 's/hello world//g' /home/user/test But the problem isn't the command, I can run the same command through terminal and it would remove the string "hello world"

public void removeString(String str, String file) throws IOException { String command = "sed -i \'s/" + str + "//g\' " + file; System.out.println(command); ProcessBuilder pb = new ProcessBuilder(command); Process p = pb.start(); } 

What is causing the process to be unable to find the file?

Source Link
Aboutblank
  • 727
  • 3
  • 14
  • 31

IOexception while runing bash commands through ProcessBuilder

I am getting a IOException when trying to run a sed command through Java using a ProcessBuilder:

ERROR: java.io.IOException: Cannot run program "sed -i 's/hello world//g' /home/user/test": error=2, No such file or directory 

The command is sed -i 's/hello world//g' /home/user/test But the problem isn't the command, I can run the same command through terminal and it would remove the string "hello world"

public void removeString(String str, String file) throws IOException { String command = "sed -i \'s/" + str + "//g\' " + file; System.out.println(command); ProcessBuilder pb = new ProcessBuilder(command); Process p = pb.start(); } 

Why can't the process find the file?