Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7672195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:13:49+00:00 2026-05-31T16:13:49+00:00

I am trying to run cut inside a java program, but I am lost

  • 0

I am trying to run “cut” inside a java program, but I am lost in terms of how to split the array of commands.
My program in the command line is the following:

cut file.txt -d' ' -f1-2  > hits.txt

And I am trying to run it inside java like this

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(new String[]{"file.txt"," -d' ' -f1-2 "," > hits.txt"});
pr.waitFor();

But I get the following runtime error

Exception in thread "main" java.io.IOException: Cannot run program "cut file.txt": java.io.IOException: error=2, No such file or directory

I attribute this error to the array of Strings I am using as exec commands. Any ideas on how to do this? Also any known documentation on the issue. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:13:50+00:00Added an answer on May 31, 2026 at 4:13 pm

    Make either an script for bash:

    "/bin/bash" "-c" "cut file.txt -d' ' -f1-2  > hits.txt"
    

    or split

    "cut" "file.txt" "-d" "' '" "-f" "1-2" 
    

    The error message clearly says:

    Cannot run program "cut file.txt"
    

    so it interprets “cut file.txt” as a single programname with a blank inside.

    Your problem starts with the redirection, because you can’t redirect the output that way:

    "cut" "file.txt" "-d" "' '" "-f" "1-2" ">" "hits.txt"
    

    You have to handle input and output streams. It might be a better idea to implement cut in Java, to get a portable solution, or call a script which the user may specify on commandline or in a config file, so that it can be adapted for Windows or other platforms.

    Calling /bin/bash and redirecting there should work – on unix like systems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to run the following command in php to run powershell command... the following
Trying to run my program in FreeBSD OS, I have the following results: $
I'm trying to run the following program, which calculates roots of polynomials of degree
I am trying to run simple shell commands in my script, but am unable
Just learning Automator here, but I'm trying to run a convert command on a
I am trying run a program from a qmake .pro file which modifies the
I am trying to run the VS 2008 SP1 installer , but it says
In Tkinter I'm trying to make it so when a command is run a
I'm trying to run a program originally tested on Matlab 6.5 on a new
Situation: I'm trying run an https store (xcart) under one domain secure.example.com and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.