How to handle whitespace in Java execution shell commands

Source: Internet
Author: User

? Runtime.getruntime (). EXEC (cmdstring), if the parameters in cmdstring at this time (such as the CP file file name) contain special symbol spaces, then an error occurs, because the source code will follow some special characters ("\t\n\r\f", Notice that it contains a space) to cmdstring into an array, so there are spaces can cause errors, this situation can be implemented by the command array, that is, the cmdstring in the array itself, do not use the source to cut off there will be no problem, for example:

ABC Af.zip is a file name

Cmdstring= "CP abc Af.zip dir" This is a problem.

string[]? Cmdarray=new string[] ("CP", "ABC Af.zip", "dir") it is OK


How to handle whitespace in Java execution shell commands

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.