seart-group / jcloc

Java wrapper for CLOC (Count Lines of Code)
MIT License
0 stars 0 forks source link

Runtime Error: "The filename, directory name, or volume label syntax is incorrect." #10

Closed Link2024 closed 4 days ago

Link2024 commented 3 weeks ago

系统:win10 我打印了execute方法中的命令是:cmd.exe /X /C "D:\tmp\cloc_out\cloc D:\tmp\cloc --json --quiet"
我放到控制台执行失败了,发现好像是缺少了cloc 这个命名。

ch.usi.si.seart jcloc 0.1.0

代码:

  System.setProperty("java.io.tmpdir", "D:\\tmp\\cloc_out");
        Path path = Paths.get("D:\\tmp\\cloc");

        String result = CLOC.command()
                .timeout(30)
                .target(path)
                .linesByLanguage()
                .toPrettyString();
        System.out.println(result);

ch.usi.si.seart.cloc.CLOCException: 'D:\tmp\cloc_out\cloc' is not recognized as an internal or external command, operable program or batch file.

at ch.usi.si.seart.cloc.CLOC.execute(CLOC.java:298)
at ch.usi.si.seart.cloc.CLOC.linesByLanguage(CLOC.java:260)
at com.dc.antlr4.antlr4util.CLOCTest.test1(CLOCTest.java:22)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)

我的系统中安装了cloc ,我单独在cmd控制台执行:cmd.exe /X /C "cloc D:\tmp\cloc --json --quiet" {"header" : { "cloc_url" : "github.com/AlDanial/cloc", "cloc_version" : "2.02", "elapsed_seconds" : 0.0284950733184814, "n_files" : 1, "n_lines" : 4605, "files_per_second" : 35.0937858212639, "lines_per_second" : 161606.88370692}, "Visual Basic .NET" :{ "nFiles": 1, "blank": 696, "comment": 965, "code": 2944}, "SUM": { "blank": 696, "comment": 965, "code": 2944, "nFiles": 1} }

dabico commented 3 weeks ago

Hello @Link2024

Thank you for submitting this. I cannot read Chinese, but I have used AI to translate your report. Feel free to correct me if I misunderstood any part of your report. From the looks of things, this seems like an OS-related issue. Pretty much all the software we develop is tested and used on Unix-based systems. As such, we typically do not focus on shipping with Windows support. Based on your error stack trace, the issue lies with Windows not being able to execute the script file bundled with the dependency. The whole idea behind bundling the script was to avoid compiling executables for different combinations of OS and architecture. That being said, I think that there should be a way for the user to specify their own executable path. This would provide more flexibility without changing the codebase too much. Something like:

CLOC.setExecutablePath(...);
Link2024 commented 3 weeks ago

Hello, Dabico After reading your answer, I couldn't find the CLOC.setExecutablePath method, so it's probably not provided in the current version. Then, regarding yesterday's issue, I will rephrase it in the hope of helping you identify the problem. Due to differences in translation software, I will provide two descriptions in Chinese and English: img_20240821 The picture is divided into two areas Area1: This is the Junit test code, which reports an error during runtime. At this point, you can look at the red box at the bottom of the debug area of the connection line, where the command: cmd. exe/X/C "D: \ tpp \ cloc_out \ cloc D: \ tpp \ cloc -- json -- quiet" is displayed. After copying this command to the cmd console, I found that it was also running incorrectly. At this point, I corrected the command by adding "cloc" before "D: \", and the command will execute normally. Modified complete command: cmd. exe/X/C "cloc D: \ tpp \ cloc_out \ cloc D: \ tpp \ cloc -- json -- quiet" As shown in the picture: 丢失命令 After looking at the source code, it was found that the problem may exist in the getBundledExecutable method of the CLOC class. If it is a Windows situation, it is necessary to add CLOC. For example: cmd. exe/X/C "cloc out_cath path -- json -- quiet". This is just my personal opinion, as currently I have only tested on Windows. If I have a Linux machine in the future, I will also test it and inform you of the test results later.

The following is in Chinese:

你好,dabico 看了你的回答,我没有找到CLOC.setExecutablePath这个方法,应该是当前版本没有提供。 然后,针对昨天的问题,我重新进行描述,希望可以帮助你们发现问题所在。由于翻译软件存在差异,我会提供中英2种描述 img_20240821

图片中分了2个区域 Area1 :这是junit测试代码,它在运行中报错,这时可以看下连接线底部debug区域的红框,此处显示了命令:cmd.exe /X /C "D:\tmp\cloc_out\cloc D:\tmp\cloc --json --quiet" 。我把这个命令复制到cmd控制台后发现运行也是错误的。  此时我修正这个命令,在"D:\"前面添加"cloc"后,这个命令就会正常执行。修改后的完整命令:cmd.exe /X /C "cloc D:\tmp\cloc_out\cloc D:\tmp\cloc --json --quiet" 如图: 丢失命令  看源码后发现问题可能存在在CLOC类的getBundledExecutable方法处,如果是windows的情况 ,需要添加cloc 。如: cmd.exe /X /C "cloc out_path path --json --quiet"。这只是我的个人观点,因为目前我只在windows上进行了测试,如果后续我有Linux机器,我也会进行测试,后面会告知测试结果。

dabico commented 4 days ago

I'm setting up Windows CI for the repository. Here is a stack trace written in English: https://github.com/seart-group/jcloc/actions/runs/10826804863/job/30038556737.

dabico commented 4 days ago

Hi @Link2024

Can you check out the latest release?

<dependency>
  <groupId>ch.usi.si.seart</groupId>
  <artifactId>jcloc</artifactId>
  <version>0.2.0</version>
</dependency>

If the same problem occurs, we'll reopen this issue. If something else is wrong, please open a new issue instead.