{"id":34243539,"url":"https://github.com/jazzhow/command4j","last_synced_at":"2025-12-16T05:03:13.887Z","repository":{"id":57720397,"uuid":"202267379","full_name":"jazzhow/command4j","owner":"jazzhow","description":"java调用命令的工具，命令行运行管理器，命令执行、停止、查询功能的工具","archived":false,"fork":false,"pushed_at":"2020-08-03T09:47:09.000Z","size":78,"stargazers_count":24,"open_issues_count":1,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-06T04:09:01.150Z","etag":null,"topics":["cmd","command4j","java","shell"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jazzhow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-14T03:27:26.000Z","updated_at":"2024-06-15T23:46:28.000Z","dependencies_parsed_at":"2022-09-02T13:10:39.844Z","dependency_job_id":null,"html_url":"https://github.com/jazzhow/command4j","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/jazzhow/command4j","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzhow%2Fcommand4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzhow%2Fcommand4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzhow%2Fcommand4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzhow%2Fcommand4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jazzhow","download_url":"https://codeload.github.com/jazzhow/command4j/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzhow%2Fcommand4j/sbom","scorecard":{"id":509631,"data":{"date":"2025-08-11","repo":{"name":"github.com/jazzhow/command4j","commit":"e5e96af23290345328bfd8d65a414a8ddababad9"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":2.3,"checks":[{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: GNU General Public License v3.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 1 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":4,"reason":"6 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-j288-q9x7-2f5v","Warn: Project is vulnerable to: GHSA-7rjr-3q55-vv33","Warn: Project is vulnerable to: GHSA-8489-44mv-ggj8","Warn: Project is vulnerable to: GHSA-jfh8-c2jp-5v3q","Warn: Project is vulnerable to: GHSA-p6xc-xr62-6r2g","Warn: Project is vulnerable to: GHSA-vwqq-5vrc-xw9h"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-20T00:13:08.585Z","repository_id":57720397,"created_at":"2025-08-20T00:13:08.585Z","updated_at":"2025-08-20T00:13:08.585Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27759613,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-16T02:00:10.477Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmd","command4j","java","shell"],"created_at":"2025-12-16T05:03:13.208Z","updated_at":"2025-12-16T05:03:13.857Z","avatar_url":"https://github.com/jazzhow.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# command4j java命令执行管理器\n ## 作用\n 调用系统的一些可执行软件，比如linux的shell脚本，windows的bat、exe可执行文件\n ## 为什么要创建此项目\n 当我们需要用java调用本地程序时，使用Runtime.getRuntime().exec(cmd)固然可以，但需要注意需要此方法返回的process\n 中获取inputStream、errorStream，需要使用两个线程从中读取内容， 如果忽略这个问题，会导致所执行的本地程序阻塞，\n 看起来就是不报错停在那里了,原因是java中会为所执行的命令开辟一个缓冲区，用于存放命令所产生的输出，包括标准输出，\n 和错误输出，如果被调用的程序产生的输出较多，而且也不从缓冲中读走，那么时间长了就会导致被调用的程序阻塞。\n 所以本项目就是为了解决此问题，而且不需要手动对inputStream、errorStream的流进行处理，使用commandManager.exec(\"一个命令\")即可，\n commandManager会自动帮你处理inputStream、errorStream的流,从而避免被调用的程序阻塞。\n\n ## 使用方法\n    引入依赖\n    \u003cdependency\u003e\n      \u003cgroupId\u003ecom.github.jazzhow\u003c/groupId\u003e\n      \u003cartifactId\u003ecommand4j\u003c/artifactId\u003e\n      \u003cversion\u003e2.0.0-RELEASE\u003c/version\u003e\n    \u003c/dependency\u003e\n    \n    ```Java\n    @Test\n    void test1() throws IOException, InterruptedException, ProcessExistException {\n        //可执行的linux程序，或windows程序，cmd1 与 cmd2执行的内容可以相同可以不同。\n        String cmd1 = \"D:/software/ffmpeg/bin/ffmpeg -i rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov -f flv -r 25 -g 25 -s 640x360 -an rtmp://localhost/live/test -vcodec copy  -f flv -an rtmp://localhost/live/test123HD\";\n        String cmd2 = \"D:/software/ffmpeg/bin/ffmpeg -i rtsp://184.72.239.149/vod/mp4://BigBuckBunny_175k.mov -f flv -r 25 -g 25 -s 640x360 -an rtmp://localhost/live/test -vcodec copy  -f flv -an rtmp://localhost/live/test123HD\";\n        CommandManager commandManager = new CommandManager();\n        //第一个参数是这个启动进程的标识,在同一个CommandManager对象中唯一，它的意义是方便通过这个标识关闭这个启动的进程，\n        //如果在同一个CommandManager对象中启动两个相同标识进程，那么会抛出一个ProcessExistException异常。\n        commandManager.exec(\"process1\", cmd1);\n        CommandProcess process2 = commandManager.exec(\"process2\", cmd2);\n        //获取commandManager中的所有的CommandProcess\n        Collection\u003cCommandProcess\u003e allProcess = commandManager.getAllProcess();\n        System.out.println(allProcess.size());\n        //process2的进程状态\n        System.out.println(process2.getProcess().isAlive());\n        //process2的执行命令\n        System.out.println(process2.getCommand());\n        //process2的执行时间\n        System.out.println(process2.getExecTime());\n        //process2的执行标识\n        System.out.println(process2.getProcessId());\n        TimeUnit.SECONDS.sleep(1);\n        //关闭process1\n        commandManager.destroy(\"process1\");\n        //关闭process2\n        commandManager.destroy(process2.getProcessId());\n        //关闭一个不存在的标识\n        CommandProcess huhuhah = commandManager.destroy(\"呼呼哈哈\");\n        System.out.println(\"destroy传入commandManager中不存在的标识返回： \" + huhuhah);\n    }\n    ```\n ## 如何让被调用的程序输出或关闭输出\n 本项目使用slf4j控制被调用的程序的输出，指定jazzhow.command4j的日志级别即可，level=debug可以看到被调用的程序的输出的输出，\n level=info只输出关键信息，等于其他请自行脑补。\n \n ## 说明\n 一个CommandManager对象可以管理多个运行的的本地程序，包括启动多个本地程序，关闭通过它启动的程序，\n 在程序退出时会自动关闭所有通过他运行的程序。\n \n 创建一个命令管理对象： CommandManager commandManager = new CommandManager();\n \n 运行本地程序： commandManager.exec(\"进程标识\", \"启动命令\"); //返回一个 java.lang.Process对象。\n \n 结束通过commandManager启动的本地程序： commandManager.destroy(\"进程标识\"); //返回一个 java.lang.Process对象。\n //commandManager如果进程标识村存在于commandManager中，返回null\n \n 获取通过commandManager启动的程序：commandManager.getAllProcess(); //返回Collection\u003cCommandProcess\u003e\n \n 停止通过commandManager所启动的所有程序：commandManager.destroyAll(); //返回Collection\u003cCommandProcess\u003e,被关闭的CommandProcess的集合\n  \n \n ## 注意\n 1、当java程序结束时，commandManager所管理的本地进程会被关闭，如果想java退出也不关闭被调用的本地程序，\n 请使用java的原生方式Runtime.getRuntime().exec(cmd)\n 2、linux下如果要结束本java程序，kill java程序是可以的，但是不要用kill -9结束，否则commandManager所管理的本地进程将\n 无法被commandManager自动关闭。\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjazzhow%2Fcommand4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjazzhow%2Fcommand4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjazzhow%2Fcommand4j/lists"}