作为 Upstart 服务启动时无法读取 UTF-8 文件名
我的 Java 程序以递归方式读取目录的内容。这是一个示例树(请注意非 ASCII 字符):
./sviluppo
./sviluppo/ciaò
./sviluppo/ciaò/subdir
./sviluppo/pippo
./sviluppo/pippo/prova2.txt <-file
./sviluppo/così
该程序作为Upstart服务启动,其配置文件名为like/init/myservice.conf
description "Private Service"
author "AD"
start on runlevel [2345]
stop on runlevel [! 2345]
exec java -jar /home/mainFind.jar >> /tmp/log.txt
当我启动服务时:
root@mdr:/tmp# service myservice start
myservice start/running, process 15344
它不会记录名称中包含非 ASCII 字符的文件名:
root@mdr:/tmp# cat /tmp/log.txt
Found dir: /mnt/sviluppo/pippo
相反,当我运行命令(作为root,以模仿当它作为服务启动时发生的情况)时,它可以正常工作,有和没有:exec
root@mdr:/tmp# java -jar /home/mainFind.jar >> /tmp/log.txt
root@mdr:/tmp# exec java -jar /home/mainFind.jar >> /tmp/log.txt
root@mdr:/tmp# cat /tmp/log.txt
Found dir: /mnt/sviluppo/ciaò
Found dir: /mnt/sviluppo/ciaò/subdir
Found dir: /mnt/sviluppo/pippo
Found dir: /mnt/sviluppo/così
为什么由同一用户运行的同一程序在Upstart服务中不起作用,但在从命令行运行时正确处理所有文件名?这是Java代码
public static void aggiungiFileDir(File f){
File[] lista= f.listFiles();
for(int i=0;i<lista.length;i++){
if(lista[i].isDirectory()){
System.out.println("Found dir: "+lista[i]);
}
}
}
其中形式参数是根目录。该函数将在每个子目录上以递归方式调用。f
编辑2:帖子ls
root@mdr:/tmp# ls -al /mnt/sviluppo
totale 20
drwx------ 5 root root 4096 nov 15 15:10 .
drwxr-xr-x 7 root root 4096 nov 9 10:43 ..
drwxr-xr-x 2 root root 4096 nov 15 15:10 ciaò
drwxr-xr-x 2 root root 4096 nov 15 11:23 così
drwxr-xr-x 2 root root 4096 nov 15 17:57 pippo