我正在尝试解析在Linux环境中运行cat /proc/mounts的结果。
当挂载包含特殊字符(如空格)时,将对其进行转义。一个这样的例子是
/home/user/media\040/image.dd /media/dd ...,其中\040实际上是一个空格。
我正在尝试用java解析它,但我不想写一个手动解析器,因为我必须相信这已经完成了,而且比我要做的更健壮。有没有专门负责解码的类?我找到了一两个八进制解码器,但它们不能处理文本和八进制混合的情况。
发布于 2013-05-17 21:19:44
我最终使用了Apache Commons Lang。
http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/StringEscapeUtils.html#unescapeJava(java.lang.String)
这似乎能正确地解决所有问题。
发布于 2012-11-27 10:45:19
您可以在C中使用getmntent解析/proc/mount。
您可以根据规则在Java中实现它:
空格(\040)、制表符(\011)、换行符(\012)和反斜杠(\134)
或者none表示交换分区。
男人得到了内容:
内容结构定义如下:
struct mntent {
char *mnt_fsname; /* name of mounted file system */
char *mnt_dir; /* file system path prefix */
char *mnt_type; /* mount type (see mntent.h) */
char *mnt_opts; /* mount options (see mntent.h) */
int mnt_freq; /* dump frequency in days */
int mnt_passno; /* pass number on parallel fsck */
};
Since fields in the mtab and fstab files are separated by whitespace, octal escapes are
used to represent the four characters space (\040), tab (\011), newline (\012) and back-
slash (\134) in those files when they occur in one of the four strings in a mntent struc-
ture. The routines addmntent() and getmntent() will convert from string representation to
escaped representation and back.另一种方式:直接解析mount的结果。将它们按" on“、"type”等拆分可能会更简单。
https://stackoverflow.com/questions/13574188
复制相似问题