开发者

use attr linux command from Java program

开发者 https://www.devze.com 2023-03-10 08:22 出处:网络
I want to attach m开发者_StackOverflow中文版eta data to afile in Unix file system. attr command lets me do that but

I want to attach m开发者_StackOverflow中文版eta data to a file in Unix file system. attr command lets me do that but the command syntax requires the path of the attached variable to be in double qoutes.

attr -s outpipe0 "/mnt/FUse/FileB" FileA

how can i Use System.Runtime.exec in java to run the above command. When ever i try to run using a string array argument I have to give the above "/mnt/FUse/FileB" which causes problem in java program as it considers the double quotes as end of string in java. I basically want to send a string argument which in itself has double quotes.

Can someone suggest a work around .

Thanks


You can escape the quotes within your literal string in Java, like this:

"\"/mnt/FUse/FileB\""

That will address your question of how to include double quotes in a string, but I doubt it will solve your program. That's because I doubt the attr program actually wants (or accepts) double quotes. Instead, the shell eats them. For example, if the command you type in the shell is the one you mentioned, the double quotes will be consumed by the shell before the arguments are passed to attr. So I have doubts that you need the double quotes at all (but if you do, see above).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号