从 Java 程序中使用 attr linux 命令

发布于 2024-11-14 09:15:40 字数 354 浏览 5 评论 0原文

我想将元数据附加到 Unix 文件系统中的文件。 attr 命令可以让我做到这一点,但是 命令语法要求附加变量的路径位于双引号中。

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

我如何在java中使用System.Runtime.exec来运行上述命令。当我尝试使用字符串数组参数运行时,我必须给出上面的 "/mnt/FUse/FileB" 这会导致 java 程序出现问题,因为它将双引号视为 java 中字符串的结尾。我基本上想发送一个本身带有双引号的字符串参数。

有人可以建议解决方法吗?

谢谢

I want to attach meta 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等往事风中吹 2024-11-21 09:15:40

您可以在 Java 中对文字字符串中的引号进行转义,如下所示:

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

这将解决您如何在字符串中包含双引号的问题,但我怀疑它能否解决您的程序。那是因为我怀疑 attr 程序实际上需要(或接受)双引号。相反,壳会吃掉它们。例如,如果您在 shell 中键入的命令是您提到的命令,则在将参数传递给 attr 之前,shell 将使用双引号。所以我怀疑你是否需要双引号(但如果你需要,请参见上文)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文