├── .asf.yaml ├── .gitattributes ├── .github ├── GH-ROBOTS.txt ├── dependabot.yml ├── pull_request_template.md └── workflows │ ├── codeql-analysis.yml │ ├── dependency-review.yml │ ├── maven.yml │ └── scorecards-analysis.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── RELEASE-NOTES.txt ├── SECURITY.md ├── pmd.xml ├── pom.xml └── src ├── assembly ├── bin.xml └── src.xml ├── changes ├── changes.xml └── release-notes.vm ├── conf ├── checkstyle-header.txt ├── checkstyle-suppressions.xml ├── checkstyle.xml ├── findbugs-exclude-filter.xml └── pmd-ruleset.xml ├── main ├── java │ └── org │ │ └── apache │ │ └── commons │ │ └── exec │ │ ├── CommandLine.java │ │ ├── DaemonExecutor.java │ │ ├── DefaultExecuteResultHandler.java │ │ ├── DefaultExecutor.java │ │ ├── ExecuteException.java │ │ ├── ExecuteResultHandler.java │ │ ├── ExecuteStreamHandler.java │ │ ├── ExecuteWatchdog.java │ │ ├── Executor.java │ │ ├── InputStreamPumper.java │ │ ├── LogOutputStream.java │ │ ├── OS.java │ │ ├── ProcessDestroyer.java │ │ ├── PumpStreamHandler.java │ │ ├── ShutdownHookProcessDestroyer.java │ │ ├── StreamPumper.java │ │ ├── ThreadUtil.java │ │ ├── TimeoutObserver.java │ │ ├── Watchdog.java │ │ ├── environment │ │ ├── DefaultProcessingEnvironment.java │ │ ├── EnvironmentUtils.java │ │ ├── OpenVmsProcessingEnvironment.java │ │ └── package-info.java │ │ ├── launcher │ │ ├── CommandLauncher.java │ │ ├── CommandLauncherFactory.java │ │ ├── CommandLauncherImpl.java │ │ ├── CommandLauncherProxy.java │ │ ├── Java13CommandLauncher.java │ │ ├── OS2CommandLauncher.java │ │ ├── VmsCommandLauncher.java │ │ ├── WinNTCommandLauncher.java │ │ └── package-info.java │ │ ├── package-info.java │ │ └── util │ │ ├── DebugUtils.java │ │ ├── MapUtils.java │ │ ├── StringUtils.java │ │ └── package-info.java └── javadoc │ └── overview.html ├── media ├── apache-commons-exec.svg ├── apache-commons.svg └── readme.txt ├── site ├── apt │ ├── commandline.apt │ ├── index.apt │ ├── technical.apt │ └── tutorial.apt ├── fml │ └── faq.fml ├── resources │ ├── download_exec.cgi │ ├── images │ │ └── logo.png │ └── profile.jacoco ├── site.xml └── xdoc │ ├── download_exec.xml │ ├── issue-tracking.xml │ ├── mail-lists.xml │ ├── security.xml │ └── testmatrix.xml └── test ├── bin ├── testme.bat ├── testme.dcl └── testme.sh ├── java └── org │ └── apache │ └── commons │ └── exec │ ├── AbstractExecTest.java │ ├── CommandLineTest.java │ ├── DefaultExecutorTest.java │ ├── LogOutputStreamTest.java │ ├── OSTest.java │ ├── PumpStreamHandlerTest.java │ ├── StandAloneTest.java │ ├── TestUtil.java │ ├── TimeoutObserverTest.java │ ├── TutorialTest.java │ ├── environment │ └── EnvironmentUtilsTest.java │ ├── issues │ ├── Exec33Test.java │ ├── Exec34Test.java │ ├── Exec36Test.java │ ├── Exec41Test.java │ ├── Exec44Test.java │ ├── Exec49Test.java │ ├── Exec57Test.java │ ├── Exec60Test.java │ ├── Exec62Test.java │ └── Exec65Test.java │ ├── launcher │ ├── AbstractCommandLauncherTest.java │ ├── CommandLauncherFactoryTest.java │ ├── CommandLauncherImplTest.java │ ├── Java13CommandLauncherTest.java │ ├── OS2CommandLauncherTest.java │ ├── VmsCommandLauncherTest.java │ └── WinNTCommandLauncherTest.java │ └── util │ ├── MapUtilTest.java │ └── StringUtilTest.java └── scripts ├── acrord32.bat ├── acrord32.sh ├── environment.bat ├── environment.dcl ├── environment.sh ├── error.bat ├── error.dcl ├── error.sh ├── forever.bat ├── forever.dcl ├── forever.sh ├── issues ├── exec-57-detached.sh ├── exec-57-nohup.sh ├── exec-62.sh └── exec-65.sh ├── ping.bat ├── ping.dcl ├── ping.sh ├── printargs.bat ├── printargs.dcl ├── printargs.sh ├── redirect.sh ├── sleep.bat ├── sleep.sh ├── standalone.sh ├── stdin.bat ├── stdin.dcl ├── stdin.sh ├── test.bat ├── test.dcl └── test.sh /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | github: 17 | description: "Apache Commons Exec" 18 | homepage: https://commons.apache.org/exec/ 19 | 20 | notifications: 21 | commits: commits@commons.apache.org 22 | issues: issues@commons.apache.org 23 | pullrequests: issues@commons.apache.org 24 | jira_options: link label 25 | jobs: notifications@commons.apache.org 26 | issues_bot_dependabot: notifications@commons.apache.org 27 | pullrequests_bot_dependabot: notifications@commons.apache.org 28 | issues_bot_codecov-commenter: notifications@commons.apache.org 29 | pullrequests_bot_codecov-commenter: notifications@commons.apache.org 30 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | * text=auto 17 | *.bat -text 18 | -------------------------------------------------------------------------------- /.github/GH-ROBOTS.txt: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | # Keeps on creating FUD PRs in test code 17 | # Does not follow Apache disclosure policies 18 | User-agent: JLLeitschuh/security-research 19 | Disallow: * 20 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | version: 2 17 | updates: 18 | - package-ecosystem: "maven" 19 | directory: "/" 20 | schedule: 21 | interval: "weekly" 22 | day: "friday" 23 | - package-ecosystem: "github-actions" 24 | directory: "/" 25 | schedule: 26 | interval: "weekly" 27 | day: "friday" 28 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | Thanks for your contribution to [Apache Commons](https://commons.apache.org/)! Your help is appreciated! 21 | 22 | Before you push a pull request, review this list: 23 | 24 | - [ ] Read the [contribution guidelines](CONTRIBUTING.md) for this project. 25 | - [ ] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself. 26 | - [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible but is a best-practice. 27 | - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. 28 | - [ ] Each commit in the pull request should have a meaningful subject line and body. Note that commits might be squashed by a maintainer on merge. 29 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | name: "CodeQL" 17 | 18 | on: 19 | push: 20 | branches: [ master ] 21 | pull_request: 22 | # The branches below must be a subset of the branches above 23 | branches: [ master ] 24 | schedule: 25 | - cron: '33 9 * * 4' 26 | 27 | permissions: 28 | contents: read 29 | 30 | jobs: 31 | analyze: 32 | name: Analyze 33 | runs-on: ubuntu-latest 34 | permissions: 35 | actions: read 36 | contents: read 37 | security-events: write 38 | 39 | strategy: 40 | fail-fast: false 41 | matrix: 42 | language: [ 'java' ] 43 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 44 | # Learn more about CodeQL language support at https://git.io/codeql-language-support 45 | 46 | steps: 47 | - name: Checkout repository 48 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 49 | with: 50 | persist-credentials: false 51 | - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 52 | with: 53 | path: ~/.m2/repository 54 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 55 | restore-keys: | 56 | ${{ runner.os }}-maven- 57 | 58 | # Initializes the CodeQL tools for scanning. 59 | - name: Initialize CodeQL 60 | uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # 3.28.18 61 | with: 62 | languages: ${{ matrix.language }} 63 | # If you wish to specify custom queries, you can do so here or in a config file. 64 | # By default, queries listed here will override any specified in a config file. 65 | # Prefix the list here with "+" to use these queries and those in the config file. 66 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 67 | 68 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 69 | # If this step fails, then you should remove it and run the build manually (see below) 70 | - name: Autobuild 71 | uses: github/codeql-action/autobuild@ff0a06e83cb2de871e5a09832bc6a81e7276941f # 3.28.18 72 | 73 | # ℹ️ Command-line programs to run using the OS shell. 74 | # 📚 https://git.io/JvXDl 75 | 76 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 77 | # and modify them (or add more) to build your code if your project 78 | # uses a compiled language 79 | 80 | #- run: | 81 | # make bootstrap 82 | # make release 83 | 84 | - name: Perform CodeQL Analysis 85 | uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # 3.28.18 86 | -------------------------------------------------------------------------------- /.github/workflows/dependency-review.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | name: 'Dependency Review' 19 | on: [pull_request] 20 | 21 | permissions: 22 | contents: read 23 | 24 | jobs: 25 | dependency-review: 26 | runs-on: ubuntu-latest 27 | steps: 28 | - name: 'Checkout Repository' 29 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 30 | - name: 'Dependency Review PR' 31 | uses: actions/dependency-review-action@da24556b548a50705dd671f47852072ea4c105d9 # v4.7.1 32 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | name: Java CI 17 | 18 | on: [push, pull_request] 19 | 20 | permissions: 21 | contents: read 22 | 23 | jobs: 24 | build: 25 | 26 | runs-on: ${{ matrix.os }} 27 | continue-on-error: ${{ matrix.experimental }} 28 | strategy: 29 | matrix: 30 | os: [ubuntu-latest, windows-latest, macos-13] 31 | java: [ 8, 11, 17, 21, 24 ] 32 | experimental: [false] 33 | include: 34 | - java: 25-ea 35 | experimental: true 36 | os: ubuntu-latest 37 | 38 | steps: 39 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 40 | with: 41 | persist-credentials: false 42 | - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 43 | with: 44 | path: ~/.m2/repository 45 | key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} 46 | restore-keys: | 47 | ${{ runner.os }}-maven- 48 | - name: Set up JDK ${{ matrix.java }} 49 | uses: actions/setup-java@c5195efecf7bdfc987ee8bae7a71cb8b11521c00 # v4.7.1 50 | with: 51 | distribution: 'temurin' 52 | java-version: ${{ matrix.java }} 53 | - name: Build with Maven 54 | run: mvn --errors --show-version --batch-mode --no-transfer-progress -Ddoclint=all 55 | -------------------------------------------------------------------------------- /.github/workflows/scorecards-analysis.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache license, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the license for the specific language governing permissions and 14 | # limitations under the license. 15 | 16 | name: "Scorecards supply-chain security" 17 | 18 | on: 19 | branch_protection_rule: 20 | schedule: 21 | - cron: "30 1 * * 6" # Weekly on Saturdays 22 | push: 23 | branches: [ "master" ] 24 | 25 | permissions: read-all 26 | 27 | jobs: 28 | 29 | analysis: 30 | 31 | name: "Scorecards analysis" 32 | runs-on: ubuntu-latest 33 | permissions: 34 | # Needed to upload the results to the code-scanning dashboard. 35 | security-events: write 36 | actions: read 37 | id-token: write # This is required for requesting the JWT 38 | contents: read # This is required for actions/checkout 39 | 40 | steps: 41 | 42 | - name: "Checkout code" 43 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 44 | with: 45 | persist-credentials: false 46 | 47 | - name: "Run analysis" 48 | uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # 2.4.2 49 | with: 50 | results_file: results.sarif 51 | results_format: sarif 52 | # A read-only PAT token, which is sufficient for the action to function. 53 | # The relevant discussion: https://github.com/ossf/scorecard-action/issues/188 54 | repo_token: ${{ secrets.GITHUB_TOKEN }} 55 | # Publish the results for public repositories to enable scorecard badges. 56 | # For more details: https://github.com/ossf/scorecard-action#publishing-results 57 | publish_results: true 58 | 59 | - name: "Upload artifact" 60 | uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # 4.6.2 61 | with: 62 | name: SARIF file 63 | path: results.sarif 64 | retention-days: 5 65 | 66 | - name: "Upload to code-scanning" 67 | uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # 3.28.18 68 | with: 69 | sarif_file: results.sarif 70 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.iml 3 | *.iws 4 | *.ipr 5 | target 6 | .swp 7 | .idea 8 | .classpath 9 | .project 10 | .settings 11 | /site-content/ 12 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache code of conduct page is [https://www.apache.org/foundation/policies/conduct.html](https://www.apache.org/foundation/policies/conduct.html). 18 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Apache Commons Exec 2 | Copyright 2005-2025 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (https://www.apache.org/). 6 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 17 | The Apache Commons security page is [https://commons.apache.org/security.html](https://commons.apache.org/security.html). 18 | -------------------------------------------------------------------------------- /pmd.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 22 | Excludes from default PMD rules. 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | bin 21 | 22 | tar.gz 23 | zip 24 | 25 | false 26 | 27 | 28 | 29 | LICENSE.txt 30 | NOTICE.txt 31 | RELEASE-NOTES.txt 32 | 33 | 34 | 35 | target 36 | 37 | 38 | *.jar 39 | 40 | 644 41 | 42 | 43 | target/site/apidocs 44 | apidocs 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /src/assembly/src.xml: -------------------------------------------------------------------------------- 1 | 17 | 20 | src 21 | 22 | tar.gz 23 | zip 24 | 25 | ${artifactId}-${commons.release.version}-src 26 | 27 | 28 | 29 | build.xml 30 | findbugs-exclude-filter.xml 31 | LICENSE.txt 32 | NOTICE.txt 33 | pmd.xml 34 | pom.xml 35 | RELEASE-NOTES.txt 36 | STATUS 37 | 38 | 39 | 40 | src 41 | 42 | 43 | test/scripts/*.sh 44 | 45 | 46 | 47 | src 48 | 49 | 775 50 | 51 | 52 | test/scripts/*.sh 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/changes/release-notes.vm: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## https://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | ## 18 | 19 | Licensed to the Apache Software Foundation (ASF) under one or more 20 | contributor license agreements. See the NOTICE file distributed with 21 | this work for additional information regarding copyright ownership. 22 | The ASF licenses this file to You under the Apache License, Version 2.0 23 | (the "License"); you may not use this file except in compliance with 24 | the License. You may obtain a copy of the License at 25 | 26 | https://www.apache.org/licenses/LICENSE-2.0 27 | 28 | Unless required by applicable law or agreed to in writing, software 29 | distributed under the License is distributed on an "AS IS" BASIS, 30 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 31 | See the License for the specific language governing permissions and 32 | limitations under the License. 33 | 34 | ${project.name} ${version} Release Notes 35 | ------------------------------------------------ 36 | 37 | The ${developmentTeam} is pleased to announce the release of ${project.name} ${version}. 38 | 39 | $introduction.replaceAll("(? 2 | 18 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/conf/findbugs-exclude-filter.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 24 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/conf/pmd-ruleset.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 20 | 21 | This ruleset checks the code for discouraged programming constructs. 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/DaemonExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | import java.nio.file.Path; 23 | import java.util.concurrent.ThreadFactory; 24 | 25 | /** 26 | * Runs daemon processes asynchronously. Callers are expected to register a {@link ProcessDestroyer} before executing any processes. 27 | * 28 | * @since 1.3 29 | */ 30 | public class DaemonExecutor extends DefaultExecutor { 31 | 32 | /** 33 | * Constructs a new builder. 34 | * 35 | * @since 1.4.0 36 | */ 37 | public static class Builder extends DefaultExecutor.Builder { 38 | 39 | /** 40 | * Constructs a new instance. 41 | */ 42 | public Builder() { 43 | // empty 44 | } 45 | 46 | /** 47 | * Creates a new configured DaemonExecutor. 48 | * 49 | * @return a new configured DaemonExecutor. 50 | */ 51 | @Override 52 | public DefaultExecutor get() { 53 | return new DaemonExecutor(getThreadFactory(), getExecuteStreamHandler(), getWorkingDirectoryPath()); 54 | } 55 | 56 | } 57 | 58 | /** 59 | * Creates a new builder. 60 | * 61 | * @return a new builder. 62 | * @since 1.4.0 63 | */ 64 | public static Builder builder() { 65 | return new Builder(); 66 | } 67 | 68 | /** 69 | * Constructs a new instance. 70 | * 71 | * @deprecated Use {@link Builder#get()}. 72 | */ 73 | @Deprecated 74 | public DaemonExecutor() { 75 | // super 76 | } 77 | 78 | private DaemonExecutor(final ThreadFactory threadFactory, final ExecuteStreamHandler executeStreamHandler, final Path workingDirectory) { 79 | super(threadFactory, executeStreamHandler, workingDirectory); 80 | } 81 | 82 | /** 83 | * Factory method to create a thread waiting for the result of an asynchronous execution. 84 | * 85 | * @param runnable the runnable passed to the thread. 86 | * @param name the name of the thread. 87 | * @return the thread. 88 | */ 89 | @Override 90 | protected Thread createThread(final Runnable runnable, final String name) { 91 | final Thread thread = super.createThread(runnable, name); 92 | thread.setDaemon(true); 93 | return thread; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/ExecuteException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | import java.io.IOException; 23 | 24 | /** 25 | * An exception indicating that the executing a subprocesses failed. 26 | */ 27 | public class ExecuteException extends IOException { 28 | 29 | /** 30 | * Comment for {@code serialVersionUID}. 31 | */ 32 | private static final long serialVersionUID = 3256443620654331699L; 33 | 34 | /** 35 | * The exit value returned by the failed process. 36 | */ 37 | private final int exitValue; 38 | 39 | /** 40 | * Constructs a new exception with the specified detail message. 41 | * 42 | * @param message The detail message. 43 | * @param exitValue The exit value. 44 | */ 45 | public ExecuteException(final String message, final int exitValue) { 46 | super(message + " (Exit value: " + exitValue + ")"); 47 | this.exitValue = exitValue; 48 | } 49 | 50 | /** 51 | * Constructs a new exception with the specified detail message and cause. 52 | * 53 | * @param message The detail message. 54 | * @param exitValue The exit value. 55 | * @param cause The underlying cause. 56 | */ 57 | public ExecuteException(final String message, final int exitValue, final Throwable cause) { 58 | super(message + " (Exit value: " + exitValue + ")", cause); 59 | this.exitValue = exitValue; 60 | } 61 | 62 | /** 63 | * Gets the exit value returned by the failed process. 64 | * 65 | * @return The exit value. 66 | */ 67 | public int getExitValue() { 68 | return exitValue; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/ExecuteResultHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | /** 23 | * The callback handlers for the result of asynchronous process execution. When a process is started asynchronously the callback provides you with the result of 24 | * the executed process, i.e. the exit value or an exception. 25 | * 26 | * @see org.apache.commons.exec.Executor#execute(CommandLine, java.util.Map, ExecuteResultHandler) 27 | */ 28 | public interface ExecuteResultHandler { 29 | 30 | /** 31 | * The asynchronous execution completed. 32 | * 33 | * @param exitValue the exit value of the sub-process. 34 | */ 35 | void onProcessComplete(int exitValue); 36 | 37 | /** 38 | * The asynchronous execution failed. 39 | * 40 | * @param e the {@code ExecuteException} containing the root cause. 41 | */ 42 | void onProcessFailed(ExecuteException e); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/ExecuteStreamHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | import java.io.IOException; 23 | import java.io.InputStream; 24 | import java.io.OutputStream; 25 | 26 | /** 27 | * Handles stream of subprocesses for {@link Executor}s. 28 | */ 29 | public interface ExecuteStreamHandler { 30 | 31 | /** 32 | * Sets a handler for the error stream of the subprocess. 33 | * 34 | * @param inputStream input stream to read from the error stream from the subprocess. 35 | * @throws IOException thrown when an I/O exception occurs. 36 | */ 37 | void setProcessErrorStream(InputStream inputStream) throws IOException; 38 | 39 | /** 40 | * Sets a handler for the input stream of the subprocess. 41 | * 42 | * @param outputStream output stream to write to the standard input stream of the subprocess. 43 | * @throws IOException thrown when an I/O exception occurs. 44 | */ 45 | void setProcessInputStream(OutputStream outputStream) throws IOException; 46 | 47 | /** 48 | * Sets a handler for the output stream of the subprocess. 49 | * 50 | * @param inputStream input stream to read from the error stream from the subprocess. 51 | * @throws IOException thrown when an I/O exception occurs. 52 | */ 53 | void setProcessOutputStream(InputStream inputStream) throws IOException; 54 | 55 | /** 56 | * Starts handling of the streams. 57 | * 58 | * @throws IOException thrown when an I/O exception occurs. 59 | */ 60 | void start() throws IOException; 61 | 62 | /** 63 | * Stops handling of the streams - will not be restarted. Will wait for pump threads to complete. 64 | * 65 | * @throws IOException thrown when an I/O exception occurs. 66 | */ 67 | void stop() throws IOException; 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/InputStreamPumper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | import java.io.InputStream; 23 | import java.io.OutputStream; 24 | 25 | import org.apache.commons.exec.util.DebugUtils; 26 | 27 | /** 28 | * Copies all data from an System.input stream to an output stream of the executed process. 29 | */ 30 | public class InputStreamPumper implements Runnable { 31 | 32 | /** 33 | * Sleep time in milliseconds. 34 | */ 35 | public static final int SLEEPING_TIME = 100; 36 | 37 | /** The input stream to pump from. */ 38 | private final InputStream is; 39 | 40 | /** The output stream to pmp into. */ 41 | private final OutputStream os; 42 | 43 | /** Flag to stop the stream pumping. */ 44 | private volatile boolean stop; 45 | 46 | /** 47 | * Create a new stream pumper. 48 | * 49 | * @param is input stream to read data from. 50 | * @param os output stream to write data to. 51 | */ 52 | public InputStreamPumper(final InputStream is, final OutputStream os) { 53 | this.is = is; 54 | this.os = os; 55 | this.stop = false; 56 | } 57 | 58 | /** 59 | * Copies data from the input stream to the output stream. Terminates as soon as the input stream is closed or an error occurs. 60 | */ 61 | @Override 62 | public void run() { 63 | try { 64 | while (!stop) { 65 | while (is.available() > 0 && !stop) { 66 | os.write(is.read()); 67 | } 68 | os.flush(); 69 | Thread.sleep(SLEEPING_TIME); 70 | } 71 | } catch (final Exception e) { 72 | final String msg = "Got exception while reading/writing the stream"; 73 | DebugUtils.handleException(msg, e); 74 | } 75 | } 76 | 77 | /** 78 | * Requests processing to stop. 79 | */ 80 | public void stopProcessing() { 81 | stop = true; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/ProcessDestroyer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | /** 23 | * Destroys all registered {@link Process} after a certain event, typically when the VM exits. 24 | * 25 | * @see ShutdownHookProcessDestroyer 26 | */ 27 | public interface ProcessDestroyer { 28 | 29 | /** 30 | * Returns {@code true} if the specified {@link Process} was successfully added to the list of processes to be destroy. 31 | * 32 | * @param process the process to add. 33 | * @return {@code true} if the specified {@link Process} was successfully added. 34 | */ 35 | boolean add(Process process); 36 | 37 | /** 38 | * Returns {@code true} if the specified {@link Process} was successfully removed from the list of processes to be destroy. 39 | * 40 | * @param process the process to remove. 41 | * @return {@code true} if the specified {@link Process} was successfully removed. 42 | */ 43 | boolean remove(Process process); 44 | 45 | /** 46 | * Returns the number of registered processes. 47 | * 48 | * @return the number of register process. 49 | */ 50 | int size(); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/ThreadUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | import java.util.concurrent.ThreadFactory; 23 | 24 | /** 25 | * Internal thread helper. 26 | */ 27 | final class ThreadUtil { 28 | 29 | /** 30 | * Creates a new Thread from the given factory and prefixes it's name with a prefix and sets the daemon flag. 31 | * 32 | * @param threadFactory the thread factory. 33 | * @param runnable The runnable to thread. 34 | * @param prefix the thread name prefix 35 | * @param daemon marks this thread as a daemon thread 36 | * @return constructed thread, or {@code null} if the request to create a thread is rejected 37 | */ 38 | static Thread newThread(final ThreadFactory threadFactory, final Runnable runnable, final String prefix, final boolean daemon) { 39 | final Thread thread = threadFactory.newThread(runnable); 40 | if (thread == null) { 41 | throw new IllegalStateException(String.format("The ThreadFactory %s cound not construct a thread for '%s'", threadFactory, prefix)); 42 | } 43 | thread.setName(prefix + thread.getName()); 44 | thread.setDaemon(daemon); 45 | return thread; 46 | } 47 | 48 | private ThreadUtil() { 49 | // empty 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/TimeoutObserver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | import java.util.function.Consumer; 23 | 24 | /** 25 | * Interface for classes that want to be notified by Watchdog. 26 | * 27 | * @see org.apache.commons.exec.Watchdog 28 | */ 29 | public interface TimeoutObserver extends Consumer { 30 | 31 | /** 32 | * Called when the watchdog times out. 33 | * 34 | * @param w the watchdog that timed out. 35 | */ 36 | void timeoutOccured(Watchdog w); 37 | 38 | /** 39 | * {@inheritDoc} 40 | * 41 | * @since 1.6.0 42 | */ 43 | @Override 44 | default void accept(final Watchdog w) { 45 | timeoutOccured(w); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/environment/EnvironmentUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.environment; 21 | 22 | import java.io.IOException; 23 | import java.util.Map; 24 | import java.util.Objects; 25 | 26 | /** 27 | * Wraps environment variables. 28 | */ 29 | public class EnvironmentUtils { 30 | 31 | /** 32 | * Default environment. 33 | */ 34 | private static final DefaultProcessingEnvironment ENVIRONMENT; 35 | 36 | static { 37 | ENVIRONMENT = new DefaultProcessingEnvironment(); 38 | } 39 | 40 | /** 41 | * Adds a key/value pair to the given environment. If the key matches an existing key, the previous setting is replaced. 42 | * 43 | * @param environment the current environment. 44 | * @param keyAndValue the key/value pair. 45 | */ 46 | public static void addVariableToEnvironment(final Map environment, final String keyAndValue) { 47 | final String[] parsedVariable = parseEnvironmentVariable(keyAndValue); 48 | environment.put(parsedVariable[0], parsedVariable[1]); 49 | } 50 | 51 | /** 52 | * Gets the list of environment variables for this process. The returned map preserves the casing of a variable's name on all platforms but obeys the casing 53 | * rules of the current platform during lookup, e.g. key names will be case-insensitive on Windows platforms. 54 | * 55 | * @return a map containing the environment variables, may be empty but never {@code null}. 56 | * @throws IOException the operation failed. 57 | */ 58 | public static Map getProcEnvironment() throws IOException { 59 | return ENVIRONMENT.getProcEnvironment(); 60 | } 61 | 62 | /** 63 | * Parses a key/value pair into a String[]. It is assumed that the ky/value pair contains a '=' character. 64 | * 65 | * @param keyAndValue the key/value pair. 66 | * @return a String[] containing the key and value. 67 | */ 68 | private static String[] parseEnvironmentVariable(final String keyAndValue) { 69 | final int index = keyAndValue.indexOf('='); 70 | if (index == -1) { 71 | throw new IllegalArgumentException("Environment variable for this platform must contain an equals sign ('=')"); 72 | } 73 | final String[] result = new String[2]; 74 | result[0] = keyAndValue.substring(0, index); 75 | result[1] = keyAndValue.substring(index + 1); 76 | return result; 77 | } 78 | 79 | private static String toString(final String value) { 80 | return Objects.toString(value, ""); 81 | } 82 | 83 | /** 84 | * Converts a variable map as an array. 85 | * 86 | * @param environment the environment to use, may be {@code null}. 87 | * @return array of key=value assignment strings or {@code null} if and only if the input map was {@code null}. 88 | */ 89 | public static String[] toStrings(final Map environment) { 90 | if (environment == null) { 91 | return null; 92 | } 93 | return environment.entrySet().stream().map(e -> toString(e.getKey()) + "=" + toString(e.getValue())).toArray(String[]::new); 94 | } 95 | 96 | /** 97 | * Hides constructor. 98 | */ 99 | private EnvironmentUtils() { 100 | // empty 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.environment; 21 | 22 | //import java.io.BufferedReader; 23 | //import java.io.IOException; 24 | //import java.util.HashMap; 25 | //import java.util.Map; 26 | // 27 | //import org.apache.commons.exec.CommandLine; 28 | 29 | /** 30 | * Helper class to determine the environment variable for VMS. 31 | * 32 | * @deprecated No longer needed. 33 | */ 34 | @Deprecated 35 | public class OpenVmsProcessingEnvironment extends DefaultProcessingEnvironment { 36 | 37 | /** 38 | * Constructs a new instance. 39 | */ 40 | public OpenVmsProcessingEnvironment() { 41 | // empty 42 | } 43 | 44 | /* 45 | * Hopefully removing super-class overrides won't cause Clirr error. If necessary can just delegate to super-class. 46 | */ 47 | 48 | // /** 49 | // * Find the list of environment variables for this process. 50 | // * 51 | // * @return a map containing the environment variables 52 | // * @throws IOException the operation failed 53 | // */ 54 | // @Override 55 | // protected Map createProcEnvironment() throws IOException { 56 | // if (procEnvironment == null) { 57 | // final BufferedReader in = runProcEnvCommand(); 58 | // procEnvironment = addVMSenvironmentVariables(new HashMap(), in); 59 | // } 60 | // 61 | // return procEnvironment; 62 | // } 63 | // 64 | // /** 65 | // * Determine the OS specific command line to get a list of environment 66 | // * variables. 67 | // * 68 | // * @return the command line 69 | // */ 70 | // @Override 71 | // protected CommandLine getProcEnvCommand() { 72 | // final CommandLine commandLine = new CommandLine("show"); 73 | // commandLine.addArgument("symbol/global"); // the parser assumes symbols are global 74 | // commandLine.addArgument("*"); 75 | // return commandLine; 76 | // } 77 | // 78 | // /** 79 | // * This method is VMS specific and used by getProcEnvironment(). Parses VMS 80 | // * symbols from {@code in} and adds them to {@code environment}. 81 | // * {@code in} is expected to be the output of "SHOW SYMBOL/GLOBAL *". 82 | // * 83 | // * @param environment the current environment 84 | // * @param in the reader from the process to determine VMS env variables 85 | // * @return the updated environment 86 | // * @throws IOException operation failed 87 | // */ 88 | // private Map addVMSenvironmentVariables(final Map environment, 89 | // final BufferedReader in) throws IOException { 90 | // String line; 91 | // while ((line = in.readLine()) != null) { 92 | // final String SEP = "=="; // global symbol separator 93 | // final int sepidx = line.indexOf(SEP); 94 | // if (sepidx > 0) { 95 | // final String name = line.substring(0, sepidx).trim(); 96 | // String value = line.substring(sepidx+SEP.length()).trim(); 97 | // value = value.substring(1,value.length()-1); // drop enclosing quotes 98 | // environment.put(name,value); 99 | // } 100 | // } 101 | // return environment; 102 | // } 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/environment/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | /** 21 | *

22 | * Queries the operating system environment. 23 | *

24 | */ 25 | package org.apache.commons.exec.environment; 26 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | import java.io.File; 23 | import java.io.IOException; 24 | import java.nio.file.Path; 25 | import java.util.Map; 26 | 27 | import org.apache.commons.exec.CommandLine; 28 | 29 | /** 30 | * Abstracts platform-dependent implementations. 31 | */ 32 | public interface CommandLauncher { 33 | 34 | /** 35 | * Executes the given command in a new process. 36 | * 37 | * @param commandLine The command to execute. 38 | * @param env The environment for the new process. If null, the environment of the current process is used. 39 | * @return the newly created process. 40 | * @throws IOException if attempting to run a command in a specific directory. 41 | */ 42 | Process exec(CommandLine commandLine, Map env) throws IOException; 43 | 44 | /** 45 | * Executes the given command in a new process, in the given working directory. 46 | * 47 | * @param commandLine The command to execute. 48 | * @param env The environment for the new process. If null, the environment of the current process is used. 49 | * @param workingDirectory The directory to start the command in. If null, the current directory is used. 50 | * @return the newly created process. 51 | * @throws IOException if trying to change directory. 52 | */ 53 | Process exec(CommandLine commandLine, Map env, File workingDirectory) throws IOException; 54 | 55 | /** 56 | * Executes the given command in a new process, in the given working directory. 57 | * 58 | * @param commandLine The command to execute. 59 | * @param env The environment for the new process. If null, the environment of the current process is used. 60 | * @param workingDirectory The directory to start the command in. If null, the current directory is used. 61 | * @return the newly created process. 62 | * @throws IOException if trying to change directory. 63 | * @since 1.5.0 64 | */ 65 | default Process exec(CommandLine commandLine, Map env, Path workingDirectory) throws IOException { 66 | return exec(commandLine, env, workingDirectory != null ? workingDirectory.toFile() : null); 67 | } 68 | 69 | /** 70 | * Tests whether {@code exitValue} signals a failure on the current system (OS specific). 71 | *

72 | * Note that this method relies on the conventions of the OS, it will return false results if the application you are running doesn't 73 | * follow these conventions. One notable exception is the Java VM provided by HP for OpenVMS - it will return 0 if successful (like on any other platform), 74 | * but this signals a failure on OpenVMS. So if you execute a new Java VM on OpenVMS, you cannot trust this method. 75 | *

76 | * 77 | * @param exitValue the exit value (return code) to be checked. 78 | * @return {@code true} if {@code exitValue} signals a failure. 79 | */ 80 | boolean isFailure(int exitValue); 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/launcher/CommandLauncherFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | import org.apache.commons.exec.OS; 23 | 24 | /** 25 | * Builds a command launcher for the OS and JVM we are running under. 26 | */ 27 | public final class CommandLauncherFactory { 28 | 29 | /** 30 | * Factory method to create an appropriate launcher. 31 | * 32 | * @return the command launcher. 33 | */ 34 | public static CommandLauncher createVMLauncher() { 35 | // Try using a JDK 1.3 launcher 36 | return OS.isFamilyOpenVms() ? new VmsCommandLauncher() : new Java13CommandLauncher(); 37 | } 38 | 39 | private CommandLauncherFactory() { 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | import java.io.File; 23 | import java.io.IOException; 24 | import java.util.Map; 25 | 26 | import org.apache.commons.exec.CommandLine; 27 | import org.apache.commons.exec.environment.EnvironmentUtils; 28 | 29 | /** 30 | * A command launcher for a particular JVM/OS platform. This class is a general purpose command launcher which can only launch commands in the current working 31 | * directory. 32 | */ 33 | public abstract class CommandLauncherImpl implements CommandLauncher { 34 | 35 | /** 36 | * Constructs a new instance. 37 | */ 38 | public CommandLauncherImpl() { 39 | // empty 40 | } 41 | 42 | @Override 43 | public Process exec(final CommandLine cmd, final Map env) throws IOException { 44 | return Runtime.getRuntime().exec(cmd.toStrings(), EnvironmentUtils.toStrings(env)); 45 | } 46 | 47 | @Override 48 | public abstract Process exec(CommandLine cmd, Map env, File workingDir) throws IOException; 49 | 50 | /** @see org.apache.commons.exec.launcher.CommandLauncher#isFailure(int) */ 51 | @Override 52 | public boolean isFailure(final int exitValue) { 53 | // non zero exit value signals failure 54 | return exitValue != 0; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | import java.io.IOException; 23 | import java.util.Map; 24 | 25 | import org.apache.commons.exec.CommandLine; 26 | 27 | /** 28 | * A command launcher that proxies another command launcher. Sub-classes override exec(args, env, workdir) 29 | */ 30 | public abstract class CommandLauncherProxy extends CommandLauncherImpl { 31 | 32 | /** The command launcher to use. */ 33 | private final CommandLauncher launcher; 34 | 35 | /** 36 | * Constructs a new instance. 37 | * 38 | * @param launcher the command launcher to use. 39 | */ 40 | public CommandLauncherProxy(final CommandLauncher launcher) { 41 | this.launcher = launcher; 42 | } 43 | 44 | /** 45 | * Launches the given command in a new process. Delegates this method to the proxied launcher. 46 | * 47 | * @param cmd the command line to execute as an array of strings. 48 | * @param env the environment to set as an array of strings. 49 | * @throws IOException forwarded from the exec method of the command launcher. 50 | */ 51 | @Override 52 | public Process exec(final CommandLine cmd, final Map env) throws IOException { 53 | return launcher.exec(cmd, env); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | import java.io.File; 23 | import java.io.IOException; 24 | import java.util.Map; 25 | 26 | import org.apache.commons.exec.CommandLine; 27 | import org.apache.commons.exec.environment.EnvironmentUtils; 28 | 29 | /** 30 | * A command launcher for Java 1.3 (and higher). Uses the built-in {@link Runtime#exec(String, String[], File)} command. 31 | */ 32 | public class Java13CommandLauncher extends CommandLauncherImpl { 33 | 34 | /** 35 | * Constructs a new instance. 36 | */ 37 | public Java13CommandLauncher() { 38 | } 39 | 40 | /** 41 | * Launches the given command in a new process, in the given working directory. 42 | * 43 | * @param cmd the command line to execute as an array of strings. 44 | * @param env the environment to set as an array of strings. 45 | * @param workingDir the working directory where the command should run. 46 | * @throws IOException probably forwarded from {@link Runtime#exec(String[], String[], File)}. 47 | */ 48 | @Override 49 | public Process exec(final CommandLine cmd, final Map env, final File workingDir) throws IOException { 50 | return Runtime.getRuntime().exec(cmd.toStrings(), EnvironmentUtils.toStrings(env), workingDir); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | import java.io.File; 23 | import java.io.IOException; 24 | import java.util.Map; 25 | 26 | import org.apache.commons.exec.CommandLine; 27 | 28 | /** 29 | * A command launcher for OS/2 that uses 'cmd.exe' when launching commands in directories other than the current working directory. 30 | *

31 | * Unlike Windows NT and friends, OS/2's cd doesn't support the /d switch to change drives and directories in one go. 32 | *

33 | *

34 | * Note that this class is currently unused because the Java13CommandLauncher is used for 0S/2. 35 | *

36 | */ 37 | public class OS2CommandLauncher extends CommandLauncherProxy { 38 | 39 | /** 40 | * Constructs a new instance. 41 | * 42 | * @param launcher the command launcher to use. 43 | */ 44 | public OS2CommandLauncher(final CommandLauncher launcher) { 45 | super(launcher); 46 | } 47 | 48 | /** 49 | * Launches the given command in a new process, in the given working directory. 50 | * 51 | * @param cmd the command line to execute as an array of strings. 52 | * @param env the environment to set as an array of strings. 53 | * @param workingDir working directory where the command should run. 54 | * @throws IOException forwarded from the exec method of the command launcher. 55 | */ 56 | @Override 57 | public Process exec(final CommandLine cmd, final Map env, final File workingDir) throws IOException { 58 | if (workingDir == null) { 59 | return exec(cmd, env); 60 | } 61 | // @formatter:off 62 | return exec(new CommandLine("cmd") 63 | .addArgument("/c") 64 | .addArguments(cmd.toStrings()), env); 65 | // @formatter:on 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | import java.io.File; 23 | import java.io.IOException; 24 | import java.util.Map; 25 | 26 | import org.apache.commons.exec.CommandLine; 27 | 28 | /** 29 | * A command launcher for Windows XP/2000/NT that uses 'cmd.exe' when launching commands in directories other than the current working directory. 30 | */ 31 | public class WinNTCommandLauncher extends CommandLauncherProxy { 32 | 33 | /** 34 | * Constructs a new instance. 35 | * 36 | * @param launcher the command launcher to use. 37 | */ 38 | public WinNTCommandLauncher(final CommandLauncher launcher) { 39 | super(launcher); 40 | } 41 | 42 | /** 43 | * Launches the given command in a new process, in the given working directory. 44 | * 45 | * @param cmd the command line to execute as an array of strings. 46 | * @param env the environment to set as an array of strings. 47 | * @param workingDir working directory where the command should run. 48 | * @throws IOException forwarded from the exec method of the command launcher. 49 | */ 50 | @Override 51 | public Process exec(final CommandLine cmd, final Map env, final File workingDir) throws IOException { 52 | if (workingDir == null) { 53 | return exec(cmd, env); 54 | } 55 | 56 | // Use cmd.exe to change to the specified directory before running the command. 57 | // @formatter:off 58 | return exec(new CommandLine("cmd") 59 | .addArgument("/c") 60 | .addArguments(cmd.toStrings()), env); 61 | // @formatter:on 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/launcher/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | /** 21 | *

22 | * Operating system dependent command launchers are abstracted by the interface {@link org.apache.commons.exec.launcher.CommandLauncher}. 23 | *

24 | */ 25 | package org.apache.commons.exec.launcher; 26 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | /** 21 | *

22 | * The main Apache Commons Exec package. 23 | *

24 | *

25 | * The main classes are {@link org.apache.commons.exec.CommandLine} and {@link org.apache.commons.exec.DefaultExecutor}. 26 | *

27 | */ 28 | package org.apache.commons.exec; 29 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/util/DebugUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.util; 21 | 22 | /** 23 | * Provides debugging support. 24 | */ 25 | public class DebugUtils { 26 | 27 | /** 28 | * System property to determine how to handle exceptions. When set to "false" we rethrow the otherwise silently catched exceptions found in the original 29 | * code. The default value is "true" 30 | */ 31 | public static final String COMMONS_EXEC_LENIENT = "org.apache.commons.exec.lenient"; 32 | 33 | /** 34 | * System property to determine how to dump an exception. When set to "true" we print any exception to stderr. The default value is "false" 35 | */ 36 | public static final String COMMONS_EXEC_DEBUG = "org.apache.commons.exec.debug"; 37 | 38 | /** 39 | * Handles an exception based on the system properties. 40 | * 41 | * @param msg message describing the problem. 42 | * @param e an exception being handled. 43 | */ 44 | public static void handleException(final String msg, final Exception e) { 45 | if (isDebugEnabled()) { 46 | System.err.println(msg); 47 | e.printStackTrace(); 48 | } 49 | if (!isLenientEnabled()) { 50 | if (e instanceof RuntimeException) { 51 | throw (RuntimeException) e; 52 | } 53 | throw new RuntimeException(e); 54 | } 55 | } 56 | 57 | /** 58 | * Determines if debugging is enabled based on the system property "COMMONS_EXEC_DEBUG". 59 | * 60 | * @return true if debug mode is enabled. 61 | */ 62 | public static boolean isDebugEnabled() { 63 | final String debug = System.getProperty(COMMONS_EXEC_DEBUG, Boolean.FALSE.toString()); 64 | return Boolean.TRUE.toString().equalsIgnoreCase(debug); 65 | } 66 | 67 | /** 68 | * Determines if lenient mode is enabled. 69 | * 70 | * @return true if lenient mode is enabled. 71 | */ 72 | public static boolean isLenientEnabled() { 73 | final String lenient = System.getProperty(COMMONS_EXEC_LENIENT, Boolean.TRUE.toString()); 74 | return Boolean.TRUE.toString().equalsIgnoreCase(lenient); 75 | } 76 | 77 | /** 78 | * Constructs a new instance. 79 | * 80 | * @deprecated Will be private in the next major version. 81 | */ 82 | @Deprecated 83 | public DebugUtils() { 84 | // empty 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/util/MapUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.util; 21 | 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | import java.util.Objects; 25 | 26 | /** 27 | * Helper classes to manipulate maps to pass substition map to the CommandLine. This class is not part of the public API and could change without warning. 28 | */ 29 | public class MapUtils { 30 | /** 31 | * Clones a map. 32 | * 33 | * @param source the Map to clone. 34 | * @param the map key type. 35 | * @param the map value type. 36 | * @return the cloned map. 37 | */ 38 | public static Map copy(final Map source) { 39 | return source == null ? null : new HashMap<>(source); 40 | } 41 | 42 | /** 43 | * Clones the lhs map and add all things from the rhs map. 44 | * 45 | * @param lhs the first map. 46 | * @param rhs the second map. 47 | * @param the map key type. 48 | * @param the map value type. 49 | * @return the merged map. 50 | */ 51 | public static Map merge(final Map lhs, final Map rhs) { 52 | Map result = null; 53 | if (lhs == null || lhs.isEmpty()) { 54 | result = copy(rhs); 55 | } else if (rhs == null || rhs.isEmpty()) { 56 | result = copy(lhs); 57 | } else { 58 | result = copy(lhs); 59 | result.putAll(rhs); 60 | } 61 | return result; 62 | } 63 | 64 | /** 65 | * Clones a map and prefixes the keys in the clone, e.g. for mapping "JAVA_HOME" to "env.JAVA_HOME" to simulate the behavior of Ant. 66 | * 67 | * @param source the source map. 68 | * @param prefix the prefix used for all names. 69 | * @param the map key type. 70 | * @param the map value type. 71 | * @return the clone of the source map. 72 | */ 73 | public static Map prefix(final Map source, final String prefix) { 74 | if (source == null) { 75 | return null; 76 | } 77 | final Map result = new HashMap<>(); 78 | for (final Map.Entry entry : source.entrySet()) { 79 | result.put(prefix + '.' + Objects.toString(entry.getKey(), ""), entry.getValue()); 80 | } 81 | return result; 82 | } 83 | 84 | /** 85 | * Constructs a new instance. 86 | * 87 | * @deprecated Will be private in the next major version. 88 | */ 89 | @Deprecated 90 | public MapUtils() { 91 | // empty 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/org/apache/commons/exec/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | /** 21 | *

22 | * Gathers utilities. 23 | *

24 | */ 25 | package org.apache.commons.exec.util; 26 | -------------------------------------------------------------------------------- /src/main/javadoc/overview.html: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | Apache Commons Exec 21 | 22 | 23 | Apache Commons Exec is a library to reliably execute external processes from within the JVM. 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/media/readme.txt: -------------------------------------------------------------------------------- 1 | ## Licensed to the Apache Software Foundation (ASF) under one 2 | ## or more contributor license agreements. See the NOTICE file 3 | ## distributed with this work for additional information 4 | ## regarding copyright ownership. The ASF licenses this file 5 | ## to you under the Apache License, Version 2.0 (the 6 | ## "License"); you may not use this file except in compliance 7 | ## with the License. You may obtain a copy of the License at 8 | ## 9 | ## https://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, 12 | ## software distributed under the License is distributed on an 13 | ## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | ## KIND, either express or implied. See the License for the 15 | ## specific language governing permissions and limitations 16 | ## under the License. 17 | ## 18 | 19 | Edit SVG files with Inkscape from https://inkscape.org/ 20 | 21 | Export an SVG file to a PNG in src/site/resources/images file of width 350 px. 22 | 23 | Using an SVG file directly can have unexpected results, using a SVG viewbox might help in the future. 24 | -------------------------------------------------------------------------------- /src/site/apt/commandline.apt: -------------------------------------------------------------------------------- 1 | ~~ 2 | ~~ Licensed to the Apache Software Foundation (ASF) under one or more 3 | ~~ contributor license agreements. See the NOTICE file distributed with 4 | ~~ this work for additional information regarding copyright ownership. 5 | ~~ The ASF licenses this file to You under the Apache License, Version 2.0 6 | ~~ (the "License"); you may not use this file except in compliance with 7 | ~~ the License. You may obtain a copy of the License at 8 | ~~ 9 | ~~ https://www.apache.org/licenses/LICENSE-2.0 10 | ~~ 11 | ~~ Unless required by applicable law or agreed to in writing, software 12 | ~~ distributed under the License is distributed on an "AS IS" BASIS, 13 | ~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ~~ See the License for the specific language governing permissions and 15 | ~~ limitations under the License. 16 | ~~ 17 | ~~ 18 | 19 | -------- 20 | Apache Commons Exec - Building the command line 21 | -------- 22 | 23 | Building the command line 24 | 25 | You have two ways to create the command line to be executed 26 | 27 | * parsing the entire command line string 28 | 29 | * building the command line incrementally 30 | 31 | * General Considerations 32 | 33 | No matter which approach you are using commons-exec does change your command 34 | line arguments in the following two cases 35 | 36 | * when the executable contains forward or backward slashes 37 | 38 | * when a command line argument contains an unquoted string 39 | 40 | The following executable arguments 41 | 42 | ---------------------------------------- 43 | ./bin/vim 44 | ---------------------------------------- 45 | 46 | will be translated under Windows to 47 | 48 | ---------------------------------------- 49 | .\\bin\\vim 50 | ---------------------------------------- 51 | 52 | * Parsing the entire command line string 53 | 54 | Parsing the command line string is easy to use but you might run into 55 | problems when tackling complex scenarios. Therefore this functionality 56 | was deprecated in the {{{https://ant.apache.org/manual/Tasks/exec.html}Ant Exec task}}. 57 | 58 | Let's have a look at few examples you would like to stick to parsing entire command 59 | line strings 60 | 61 | ** Spaces in command line arguments 62 | 63 | Here we would like to invoke a batch file which contains spaces in the path 64 | 65 | ---------------------------------------- 66 | cmd.exe /C c:\was51\Web Sphere\AppServer\bin\versionInfo.bat 67 | ---------------------------------------- 68 | 69 | Due to the space in the file name we have to quote the file name either with 70 | single or double quotes otherwise it falls apart into two command line 71 | arguments and . 72 | 73 | ---------------------------------------- 74 | String line = "cmd.exe /C 'c:\\was51\\Web Sphere\\AppServer\\bin\\versionInfo.bat'"; 75 | ---------------------------------------- 76 | 77 | * Building the Command Line Incrementally 78 | 79 | This is the recommended approach and caters also for pre-quoted command 80 | line argument. 81 | 82 | ** A simple example 83 | 84 | Now we would like to build the following command line 85 | 86 | ---------------------------------------- 87 | runMemorySud.cmd 10 30 -XX:+UseParallelGC -XX:ParallelGCThreads=2 88 | ---------------------------------------- 89 | 90 | using the following code snippet 91 | 92 | ---------------------------------------- 93 | CommandLine cmdl = new CommandLine("runMemorySud.cmd"); 94 | cmdl.addArgument("10"); 95 | cmdl.addArgument("30"); 96 | cmdl.addArgument("-XX:+UseParallelGC"); 97 | cmdl.addArgument("-XX:ParallelGCThreads=2"); 98 | ---------------------------------------- 99 | 100 | ** A complex example 101 | 102 | Now let's have a look at the following command line found somewhere in the 103 | internet 104 | 105 | ---------------------------------------- 106 | dotnetfx.exe /q:a /c:"install.exe /l ""\Documents and Settings\myusername\Local Settings\Temp\netfx.log"" /q" 107 | ---------------------------------------- 108 | 109 | The following code snippet builds the command line using pre-quoted 110 | arguments and variable expansion 111 | 112 | ---------------------------------------- 113 | File file = new File("/Documents and Settings/myusername/Local Settings/Temp/netfx.log"); 114 | Map map = new HashMap(); 115 | map.put("FILE", file); 116 | 117 | cmdl = new CommandLine("dotnetfx.exe"); 118 | cmdl.setSubstitutionMap(map); 119 | cmdl.addArgument("/q:a", false); 120 | cmdl.addArgument("/c:\"install.exe /l \"\"${FILE}\"\" /q\"", false); 121 | ---------------------------------------- 122 | 123 | * For the Desperate 124 | 125 | When crafting a command line it would be really helpful to see what 126 | happens to your command line arguments. The following scripts can be 127 | invoked to print your command line arguments for Unix 128 | 129 | ---------------------------------------- 130 | while [ $# -gt 0 ] 131 | do 132 | echo "$1" 133 | shift 134 | done 135 | ---------------------------------------- 136 | 137 | and for Windows 138 | 139 | ---------------------------------------- 140 | :Loop 141 | IF [%1]==[] GOTO Continue 142 | @ECHO "%1" 143 | SHIFT 144 | GOTO Loop 145 | :Continue 146 | ---------------------------------------- 147 | 148 | -------------------------------------------------------------------------------- /src/site/apt/index.apt: -------------------------------------------------------------------------------- 1 | ~~ 2 | ~~ Licensed to the Apache Software Foundation (ASF) under one or more 3 | ~~ contributor license agreements. See the NOTICE file distributed with 4 | ~~ this work for additional information regarding copyright ownership. 5 | ~~ The ASF licenses this file to You under the Apache License, Version 2.0 6 | ~~ (the "License"); you may not use this file except in compliance with 7 | ~~ the License. You may obtain a copy of the License at 8 | ~~ 9 | ~~ https://www.apache.org/licenses/LICENSE-2.0 10 | ~~ 11 | ~~ Unless required by applicable law or agreed to in writing, software 12 | ~~ distributed under the License is distributed on an "AS IS" BASIS, 13 | ~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ~~ See the License for the specific language governing permissions and 15 | ~~ limitations under the License. 16 | ~~ 17 | ~~ 18 | 19 | -------- 20 | Apache Commons Exec 21 | -------- 22 | 23 | Apache Commons Exec 24 | 25 | * Rationale 26 | 27 | Executing external processes from Java is a well-known problem area. It is inheriently platform dependent and requires 28 | the developer to know and test for platform specific behaviors, for example using cmd.exe on Windows or limited buffer 29 | sizes causing deadlocks. The JRE support for this is very limited, albeit better with the Java SE 1.5 30 | ProcessBuilder class. 31 | 32 | Reliably executing external processes can also require knowledge of the environment variables before or after the 33 | command is executed. In J2SE 1.1-1.4 there is not support for this, since the method, <<>>, for 34 | retrieving environment variables is deprecated. 35 | 36 | There are currently several different libraries that for their own purposes have implemented frameworks around 37 | <<>> to handle the various issues outlined above. The proposed project should aim at coordinating and 38 | learning from these initiatives to create and maintain a simple, reusable and well-tested package. Since some of the 39 | more problematic platforms are not readily available, it is our hope that the broad Apache community can be a 40 | great help. 41 | 42 | * Scope of the package 43 | 44 | The package shall create and maintain a process execution package written in the Java language to be distributed 45 | under the ASF license. The Java code might also be complemented with scripts (e.g. Perl scripts) to fully enable 46 | execution on some operating systems. The package should aim for supporting a wide range of operating systems while 47 | still having a consistent API for all platforms. 48 | 49 | * Releases 50 | 51 | * Version 1.4.0 requires Java 8 or above. 52 | 53 | * Version 1.3 is JDK 1.5 compatible. 54 | 55 | * Version 1.2 is JDK 1.3 compatible. 56 | 57 | * Version 1.1 is JDK 1.3 compatible. 58 | 59 | * See the {{{https://archive.apache.org/dist/commons/exec/}Apache Archive}}. 60 | 61 | -------------------------------------------------------------------------------- /src/site/apt/technical.apt: -------------------------------------------------------------------------------- 1 | ~~ 2 | ~~ Licensed to the Apache Software Foundation (ASF) under one or more 3 | ~~ contributor license agreements. See the NOTICE file distributed with 4 | ~~ this work for additional information regarding copyright ownership. 5 | ~~ The ASF licenses this file to You under the Apache License, Version 2.0 6 | ~~ (the "License"); you may not use this file except in compliance with 7 | ~~ the License. You may obtain a copy of the License at 8 | ~~ 9 | ~~ https://www.apache.org/licenses/LICENSE-2.0 10 | ~~ 11 | ~~ Unless required by applicable law or agreed to in writing, software 12 | ~~ distributed under the License is distributed on an "AS IS" BASIS, 13 | ~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ~~ See the License for the specific language governing permissions and 15 | ~~ limitations under the License. 16 | ~~ 17 | ~~ 18 | 19 | -------- 20 | Apache Commons Exec Technical Details 21 | -------- 22 | 23 | Apache Commons Exec 24 | 25 | * An Implementation Overview 26 | 27 | Looking at commons-exec can be a bit daunting the first time therefore an 28 | overview of the implementation helps. 29 | 30 | ** DefaultExecutor 31 | The main class is <> where you defined the command line 32 | of the sub-process to be executed. 33 | 34 | -------------------------------------------------------------------------------- /src/site/fml/faq.fml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 21 | 22 | 23 | 24 | General 25 | 26 | How mature is it? 27 | 28 |

The code was ported from Apache Ant and extensively 29 | tested on various platforms. So there is no reason not to use it and it is very likely 30 | better than any home-grown library.

31 |
32 |
33 | 34 | How do I create a complex command line using single and double quotes? 35 | 36 |

It is recommended to use CommandLine.addArgument() instead of CommandLine.parse(). Using 37 | CommandLine.parse() the implementation tries to figure out the correct quoting using your 38 | arguments and file names containing spaces. With CommandLine.addArgument() you can 39 | enable/disable quoting depending on your requirements. Having said that this is the 40 | recommended approach using Ant anyway.

41 |
42 |
43 | 44 | Are child processes automatically killed? 45 | 46 |

This functionality is largely depend on the operating system - on Unix it works 47 | mostly and under Windows not at all (see 48 | Bug 4770092). In terms of stability and cross-platform support try to start your applications directly and 49 | avoid various wrapper scripts.

50 |
51 |
52 | 53 | Does commons-exec support java-gcj? 54 | 55 |

Well - one out of 55 regression tests fails. The 56 | EnvironmentUtilTest.testGetProcEnvironment() test fails because it detects no environment 57 | variables for the current process but there must be one since we require JAVA_HOME to be 58 | set. Not sure if this is a plain bug in java-gcj-4.2.1 or requires a work around in 59 | commons-exec

60 |
61 |
62 | 63 | 64 | How to test commons-exec on my environment? 65 | 66 |

Assuming that you have an environment not listed on the test 67 | matrix and want to make sure that everything works fine you can run easily run the 68 | regression tests. Make a SVN checkout and run 'ant test-distribution' to create the test 69 | distribution in './target'. On a production box downloading the ready-to-run test 70 | distribution might be even more handy ( 71 | https://people.apache.org/~sgoeschl/download/commons-exec/). Unpack the 'zip' or 72 | 'tar.gz' file and start the tests. Independent from the result we very much appreciate 73 | your feedback ... :-)

74 |
75 | Why is the regression test broken on my Unix box 76 | 77 |

Please check if the shell scripts under "./src/test/script" are executable - assuming 78 | that they are not executable the "testExecute*" and "testExecuteAsync*" test will 79 | fail. We try very hard to keep the executable bit but they have somehow the tendency 80 | to be lost ... 81 |

82 |
83 |
84 |
85 |
86 | -------------------------------------------------------------------------------- /src/site/resources/download_exec.cgi: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Just call the standard mirrors.cgi script. It will use download.html 3 | # as the input template. 4 | exec /www/www.apache.org/dyn/mirrors/mirrors.cgi $* -------------------------------------------------------------------------------- /src/site/resources/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/commons-exec/508905df67badce37d0871b7afa4554d50b9b7eb/src/site/resources/images/logo.png -------------------------------------------------------------------------------- /src/site/resources/profile.jacoco: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # https://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ----------------------------------------------------------------------------- 16 | # 17 | # Empty file used to automatically trigger JaCoCo profile from commons parent pom 18 | -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 38 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /src/site/xdoc/security.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 23 | 24 | Apache Commons Security Reports 25 | Apache Commons Team 26 | 27 | 28 |
29 |

30 | For information about reporting or asking questions about security, please see 31 | Apache Commons Security. 32 |

33 |

This page lists all security vulnerabilities fixed in released versions of this component. 34 |

35 |

Please note that binary patches are never provided. If you need to apply a source code patch, use the building instructions for the component version 36 | that you are using. 37 |

38 |

39 | If you need help on building this component or other help on following the instructions to mitigate the known vulnerabilities listed here, please send 40 | your questions to the public 41 | user mailing list. 42 |

43 |

If you have encountered an unlisted security vulnerability or other unexpected behavior that has security impact, or if the descriptions here are 44 | incomplete, please report them privately to the Apache Security Team. Thank you. 45 |

46 |
47 |
48 |

None.

49 |
50 | 51 |
52 | -------------------------------------------------------------------------------- /src/test/bin/testme.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | REM 3 | REM Licensed to the Apache Software Foundation (ASF) under one or more 4 | REM contributor license agreements. See the NOTICE file distributed with 5 | REM this work for additional information regarding copyright ownership. 6 | REM The ASF licenses this file to You under the Apache License, Version 2.0 7 | REM (the "License"); you may not use this file except in compliance with 8 | REM the License. You may obtain a copy of the License at 9 | REM 10 | REM https://www.apache.org/licenses/LICENSE-2.0 11 | REM 12 | REM Unless required by applicable law or agreed to in writing, software 13 | REM distributed under the License is distributed on an "AS IS" BASIS, 14 | REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | REM See the License for the specific language governing permissions and 16 | REM limitations under the License. 17 | REM 18 | 19 | mkdir target 20 | "%JAVA_HOME%\bin\java" -cp .\lib\junit-4.11.jar;.\lib\commons-exec-@VERSION@-tests.jar;.\lib\commons-exec-@VERSION@.jar org.apache.commons.exec.TestRunner -------------------------------------------------------------------------------- /src/test/bin/testme.dcl: -------------------------------------------------------------------------------- 1 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2 | $! 3 | $! Licensed to the Apache Software Foundation (ASF) under one or more 4 | $! contributor license agreements. See the NOTICE file distributed with 5 | $! this work for additional information regarding copyright ownership. 6 | $! The ASF licenses this file to You under the Apache License, Version 2.0 7 | $! (the "License"); you may not use this file except in compliance with 8 | $! the License. You may obtain a copy of the License at 9 | $! 10 | $! https://www.apache.org/licenses/LICENSE-2.0 11 | $! 12 | $! Unless required by applicable law or agreed to in writing, software 13 | $! distributed under the License is distributed on an "AS IS" BASIS, 14 | $! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | $! See the License for the specific language governing permissions and 16 | $! limitations under the License. 17 | $! 18 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 19 | $! 20 | $! Run the test suite 21 | $! 22 | $ create/directory [.target] 23 | $ java "-Dorg.apache.commons.exec.lenient=false" "-Dorg.apache.commons.exec.debug=false" - 24 | -cp "./lib/junit-3.8.1.jar:./lib/commons-exec-${project.version}-tests.jar:./lib/commons-exec-${project.version}.jar" - 25 | "org.apache.commons.exec.TestRunner" -------------------------------------------------------------------------------- /src/test/bin/testme.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | chmod ug+x ./src/test/scripts/*.sh 21 | mkdir target 22 | $JAVA_HOME/bin/java -Dorg.apache.commons.exec.lenient=false -Dorg.apache.commons.exec.debug=false -cp ./lib/junit-3.8.1.jar:./lib/commons-exec-${project.version}-tests.jar:./lib/commons-exec-${project.version}.jar org.apache.commons.exec.TestRunner -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/AbstractExecTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | import java.io.File; 23 | 24 | /** 25 | * Abstracts tests. 26 | */ 27 | public abstract class AbstractExecTest { 28 | 29 | /** 30 | * Default test timeout in milliseconds. 31 | */ 32 | public static final int TEST_TIMEOUT = 15_000; 33 | 34 | /** 35 | * Watchdog timeout in milliseconds. 36 | */ 37 | public static final int WATCHDOG_TIMEOUT = 3_000; 38 | 39 | private final File testDir = new File("src/test/scripts"); 40 | 41 | /** 42 | * Resolve the OS-specific test file to execute. 43 | */ 44 | protected File resolveTestScript(final String baseName) { 45 | final File result = TestUtil.resolveScriptFileForOS(testDir + "/" + baseName); 46 | if (!result.exists()) { 47 | throw new IllegalArgumentException("Unable to find the following file: " + result.getAbsolutePath()); 48 | } 49 | return result; 50 | } 51 | 52 | /** 53 | * Resolve the OS-specific test file to execute. 54 | */ 55 | protected File resolveTestScript(final String directoryName, final String baseName) { 56 | final File result = TestUtil.resolveScriptFileForOS(testDir + "/" + directoryName + "/" + baseName); 57 | if (!result.exists()) { 58 | throw new IllegalArgumentException("Unable to find the following file: " + result.getAbsolutePath()); 59 | } 60 | return result; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/LogOutputStreamTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | package org.apache.commons.exec; 20 | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; 22 | import static org.junit.jupiter.api.Assertions.assertFalse; 23 | 24 | import java.io.File; 25 | import java.io.OutputStream; 26 | import java.nio.charset.Charset; 27 | import java.nio.charset.StandardCharsets; 28 | import java.nio.file.Path; 29 | 30 | import org.junit.jupiter.api.AfterEach; 31 | import org.junit.jupiter.api.Disabled; 32 | import org.junit.jupiter.api.Test; 33 | import org.junitpioneer.jupiter.SetSystemProperty; 34 | 35 | /** 36 | * Test the LogOutputStream. 37 | */ 38 | // turn on debug mode and throw an exception for each encountered problem 39 | @SetSystemProperty(key = "org.apache.commons.exec.lenient", value = "false") 40 | @SetSystemProperty(key = "org.apache.commons.exec.debug", value = "true") 41 | public class LogOutputStreamTest { 42 | 43 | private static final class SystemLogOutputStream extends LogOutputStream { 44 | 45 | private StringBuffer output = new StringBuffer(); 46 | 47 | private SystemLogOutputStream(final int level) { 48 | super(level); 49 | } 50 | 51 | private SystemLogOutputStream(final int level, final Charset charset) { 52 | super(level, charset); 53 | } 54 | 55 | private String getOutput() { 56 | return output.toString(); 57 | } 58 | 59 | @Override 60 | protected void processLine(final String line, final int level) { 61 | System.out.println(line); 62 | output.append(line); 63 | } 64 | } 65 | 66 | private final Executor exec = DefaultExecutor.builder().get(); 67 | private final File testDir = new File("src/test/scripts"); 68 | private OutputStream systemOut; 69 | 70 | private final Path environmentScript = TestUtil.resolveScriptPathForOS(testDir + "/environment"); 71 | 72 | private final Path utf8CharacterScript = TestUtil.resolveScriptPathForOS(testDir + "/utf8Characters"); 73 | 74 | @AfterEach 75 | public void tearDown() throws Exception { 76 | if (this.systemOut != null) { 77 | this.systemOut.close(); 78 | } 79 | } 80 | 81 | @Test 82 | public void testStdout() throws Exception { 83 | this.systemOut = new SystemLogOutputStream(1); 84 | this.exec.setStreamHandler(new PumpStreamHandler(systemOut, systemOut)); 85 | 86 | final CommandLine cl = new CommandLine(environmentScript); 87 | final int exitValue = exec.execute(cl); 88 | assertFalse(exec.isFailure(exitValue)); 89 | } 90 | 91 | @Test 92 | @Disabled("The file utf8CharacterScript is missing from the repository and is not in its history") 93 | public void testStdoutWithUTF8Characters() throws Exception { 94 | this.systemOut = new SystemLogOutputStream(1, StandardCharsets.UTF_8); 95 | this.exec.setStreamHandler(new PumpStreamHandler(systemOut, systemOut)); 96 | 97 | final CommandLine cl = new CommandLine(utf8CharacterScript); 98 | final int exitValue = exec.execute(cl); 99 | assertFalse(exec.isFailure(exitValue)); 100 | assertEquals("This string contains UTF-8 characters like the see no evil monkey \uD83D\uDE48 and the right single quotation mark \u2019", 101 | ((SystemLogOutputStream) systemOut).getOutput()); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/OSTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertFalse; 23 | import static org.junit.jupiter.api.Assertions.assertTrue; 24 | 25 | import org.junit.jupiter.api.Test; 26 | import org.junit.jupiter.api.condition.EnabledOnOs; 27 | 28 | /** 29 | * Tests {@link OS}. 30 | */ 31 | public class OSTest { 32 | 33 | @Test 34 | public void testIsArch() { 35 | assertFalse(OS.isArch(null)); 36 | assertFalse(OS.isArch("....")); 37 | } 38 | 39 | @Test 40 | @EnabledOnOs(org.junit.jupiter.api.condition.OS.MAC) 41 | public void testIsArchMacOs() { 42 | assertFalse(OS.isFamilyDOS()); 43 | assertTrue(OS.isFamilyMac()); 44 | assertFalse(OS.isFamilyNetware()); 45 | assertFalse(OS.isFamilyOpenVms()); 46 | assertFalse(OS.isFamilyOS2()); 47 | assertFalse(OS.isFamilyOS400()); 48 | assertFalse(OS.isFamilyTandem()); 49 | assertTrue(OS.isFamilyUnix()); 50 | assertFalse(OS.isFamilyWin9x()); 51 | assertFalse(OS.isFamilyWindows()); 52 | assertFalse(OS.isFamilyWinNT()); 53 | assertFalse(OS.isFamilyZOS()); 54 | } 55 | 56 | @Test 57 | public void testIsVersion() { 58 | assertFalse(OS.isVersion(null)); 59 | assertFalse(OS.isVersion("....")); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/PumpStreamHandlerTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertEquals; 23 | 24 | import java.time.Duration; 25 | 26 | import org.junit.jupiter.api.Test; 27 | 28 | /** 29 | * Tests {@link PumpStreamHandler}. 30 | */ 31 | public class PumpStreamHandlerTest { 32 | 33 | @Test 34 | public void testSetStopTimeout() { 35 | final PumpStreamHandler handler = new PumpStreamHandler(); 36 | assertEquals(Duration.ZERO, handler.getStopTimeout()); 37 | handler.setStopTimeout(Duration.ofMinutes(1)); 38 | assertEquals(Duration.ofMinutes(1), handler.getStopTimeout()); 39 | handler.setStopTimeout(0); 40 | assertEquals(Duration.ZERO, handler.getStopTimeout()); 41 | handler.setStopTimeout(60_001); 42 | assertEquals(Duration.ofMillis(60_001), handler.getStopTimeout()); 43 | handler.setStopTimeout(null); 44 | assertEquals(Duration.ZERO, handler.getStopTimeout()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/StandAloneTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertTrue; 23 | 24 | import java.io.File; 25 | import java.nio.file.Path; 26 | import java.nio.file.Paths; 27 | import java.util.concurrent.Executors; 28 | 29 | import org.junit.jupiter.api.Test; 30 | import org.junit.jupiter.api.condition.DisabledOnOs; 31 | import org.junitpioneer.jupiter.SetSystemProperty; 32 | 33 | /** 34 | * Placeholder for mailing list question - provided a minimal test case to answer the question as sel-contained regression test. 35 | */ 36 | @SetSystemProperty(key = "org.apache.commons.exec.lenient", value = "false") 37 | @SetSystemProperty(key = "org.apache.commons.exec.debug", value = "true") 38 | public class StandAloneTest { 39 | 40 | @Test 41 | @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) 42 | public void testDefaultExecutorBuilderFromFile() throws Exception { 43 | final Path testScript = TestUtil.resolveScriptPathForOS("./src/test/scripts/standalone"); 44 | // @formatter:off 45 | final Executor exec = DefaultExecutor.builder() 46 | .setThreadFactory(Executors.defaultThreadFactory()) 47 | .setExecuteStreamHandler(new PumpStreamHandler()) 48 | .setWorkingDirectory(new File(".")) 49 | .get(); 50 | // @formatter:on 51 | exec.setStreamHandler(new PumpStreamHandler()); 52 | final CommandLine cl = new CommandLine(testScript); 53 | exec.execute(cl); 54 | assertTrue(new File("./target/mybackup.gz").exists()); 55 | } 56 | 57 | @Test 58 | @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) 59 | public void testDefaultExecutorBuilderFromPath() throws Exception { 60 | final Path testScript = TestUtil.resolveScriptPathForOS("./src/test/scripts/standalone"); 61 | // @formatter:off 62 | final Executor exec = DefaultExecutor.builder() 63 | .setThreadFactory(Executors.defaultThreadFactory()) 64 | .setExecuteStreamHandler(new PumpStreamHandler()) 65 | .setWorkingDirectory(Paths.get(".")) 66 | .get(); 67 | // @formatter:on 68 | exec.setStreamHandler(new PumpStreamHandler()); 69 | final CommandLine cl = new CommandLine(testScript); 70 | exec.execute(cl); 71 | assertTrue(new File("./target/mybackup.gz").exists()); 72 | } 73 | 74 | @Test 75 | @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) 76 | public void testDefaultExecutorDefaultBuilder() throws Exception { 77 | final Path testScript = TestUtil.resolveScriptPathForOS("./src/test/scripts/standalone"); 78 | final Executor exec = DefaultExecutor.builder().get(); 79 | exec.setStreamHandler(new PumpStreamHandler()); 80 | final CommandLine cl = new CommandLine(testScript); 81 | exec.execute(cl); 82 | assertTrue(new File("./target/mybackup.gz").exists()); 83 | } 84 | 85 | @Test 86 | @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) 87 | public void testDefaultExecutorFromFile() throws Exception { 88 | final Path testScript = TestUtil.resolveScriptPathForOS("./src/test/scripts/standalone"); 89 | final Executor exec = new DefaultExecutor(); 90 | exec.setStreamHandler(new PumpStreamHandler()); 91 | final CommandLine cl = new CommandLine(testScript); 92 | exec.execute(cl); 93 | assertTrue(new File("./target/mybackup.gz").exists()); 94 | } 95 | 96 | @Test 97 | @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) 98 | public void testDefaultExecutorFromPath() throws Exception { 99 | final Path testScript = TestUtil.resolveScriptPathForOS("./src/test/scripts/standalone"); 100 | final Executor exec = new DefaultExecutor(); 101 | exec.setStreamHandler(new PumpStreamHandler()); 102 | final CommandLine cl = new CommandLine(testScript); 103 | exec.execute(cl); 104 | assertTrue(new File("./target/mybackup.gz").exists()); 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/TestUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | import static org.junit.jupiter.api.Assertions.fail; 23 | 24 | import java.io.File; 25 | import java.nio.file.Path; 26 | import java.nio.file.Paths; 27 | 28 | /** 29 | */ 30 | public final class TestUtil { 31 | 32 | /** 33 | * Gets success and fail return codes used by the test scripts 34 | * 35 | * @return int array[2] = {ok, success} 36 | */ 37 | public static int[] getTestScriptCodesForOS() { 38 | if (OS.isFamilyWindows()) { 39 | return new int[] { 0, 1 }; 40 | } 41 | if (OS.isFamilyUnix()) { 42 | return new int[] { 0, 1 }; 43 | } 44 | if (OS.isFamilyOpenVms()) { 45 | return new int[] { 1, 2 }; 46 | } 47 | fail("Test not supported for this OS"); 48 | return null; // unreachable. 49 | } 50 | 51 | public static File resolveScriptFileForOS(final String script) { 52 | return resolveScriptPathForOS(script).toFile(); 53 | } 54 | 55 | public static Path resolveScriptPathForOS(final String script) { 56 | if (OS.isFamilyWindows()) { 57 | return Paths.get(script + ".bat"); 58 | } 59 | if (OS.isFamilyUnix()) { 60 | return Paths.get(script + ".sh"); 61 | } 62 | if (OS.isFamilyOpenVms()) { 63 | return Paths.get(script + ".dcl"); 64 | } 65 | fail("Test not supported for this OS"); 66 | return null; // unreachable. 67 | } 68 | 69 | private TestUtil() { 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/TimeoutObserverTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertFalse; 23 | import static org.junit.jupiter.api.Assertions.assertTrue; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | /** 28 | * Tests {@link TimeoutObserver}. 29 | */ 30 | public class TimeoutObserverTest { 31 | 32 | static class TimeoutObserverFixture implements TimeoutObserver { 33 | 34 | private boolean b; 35 | 36 | @Override 37 | public void timeoutOccured(final Watchdog w) { 38 | b = true; 39 | } 40 | } 41 | 42 | private final TimeoutObserverFixture tof = new TimeoutObserverFixture(); 43 | 44 | @Test 45 | public void testAccept() { 46 | assertFalse(tof.b); 47 | tof.accept(null); 48 | assertTrue(tof.b); 49 | } 50 | 51 | @Test 52 | public void testTimeoutOccured() { 53 | assertFalse(tof.b); 54 | tof.timeoutOccured(null); 55 | assertTrue(tof.b); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/issues/Exec33Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.issues; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertFalse; 23 | 24 | import java.io.File; 25 | 26 | import org.apache.commons.exec.CommandLine; 27 | import org.apache.commons.exec.DefaultExecutor; 28 | import org.apache.commons.exec.Executor; 29 | import org.apache.commons.exec.PumpStreamHandler; 30 | import org.apache.commons.exec.TestUtil; 31 | import org.junit.jupiter.api.Test; 32 | 33 | /** 34 | * Test the patch for EXEC-33 (https://issues.apache.org/jira/browse/EXEC-33) 35 | * 36 | * PumpStreamHandler hangs if System.in is redirect to process input stream. 37 | */ 38 | public class Exec33Test { 39 | 40 | private final Executor exec = DefaultExecutor.builder().get(); 41 | private final File testDir = new File("src/test/scripts"); 42 | private final File testScript = TestUtil.resolveScriptFileForOS(testDir + "/test"); 43 | 44 | @Test 45 | public void testExec33() throws Exception { 46 | final CommandLine cl = new CommandLine(testScript); 47 | final PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(System.out, System.err, System.in); 48 | final DefaultExecutor executor = DefaultExecutor.builder().get(); 49 | executor.setStreamHandler(pumpStreamHandler); 50 | final int exitValue = executor.execute(cl); 51 | assertFalse(exec.isFailure(exitValue)); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/issues/Exec34Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.issues; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertFalse; 23 | import static org.junit.jupiter.api.Assertions.assertNotNull; 24 | import static org.junit.jupiter.api.Assertions.assertTrue; 25 | 26 | import java.io.File; 27 | 28 | import org.apache.commons.exec.CommandLine; 29 | import org.apache.commons.exec.DefaultExecuteResultHandler; 30 | import org.apache.commons.exec.DefaultExecutor; 31 | import org.apache.commons.exec.ExecuteWatchdog; 32 | import org.apache.commons.exec.Executor; 33 | import org.apache.commons.exec.TestUtil; 34 | import org.junit.jupiter.api.Test; 35 | 36 | /** 37 | * EXEC-34 https://issues.apache.org/jira/browse/EXEC-34 38 | */ 39 | public class Exec34Test { 40 | 41 | private final Executor exec = DefaultExecutor.builder().get(); 42 | private final File testDir = new File("src/test/scripts"); 43 | private final File pingScript = TestUtil.resolveScriptFileForOS(testDir + "/ping"); 44 | 45 | /** 46 | * 47 | * Race condition prevent watchdog working using ExecuteStreamHandler. The test fails because when watchdog.destroyProcess() is invoked the external process 48 | * is not bound to the watchdog yet. 49 | * 50 | * @throws Exception the test failed 51 | */ 52 | @Test 53 | public void testExec34Part1() throws Exception { 54 | 55 | final CommandLine cmdLine = new CommandLine(pingScript); 56 | cmdLine.addArgument("10"); // sleep 10 seconds 57 | 58 | final ExecuteWatchdog watchdog = new ExecuteWatchdog(Integer.MAX_VALUE); 59 | final DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler(); 60 | exec.setWatchdog(watchdog); 61 | exec.execute(cmdLine, handler); 62 | assertTrue(watchdog.isWatching()); 63 | watchdog.destroyProcess(); 64 | assertTrue(watchdog.killedProcess(), "Watchdog should have killed the process"); 65 | assertFalse(watchdog.isWatching(), "Watchdog is no longer watching the process"); 66 | } 67 | 68 | /** 69 | * Some user waited for an asynchronous process using watchdog.isWatching() which is now properly implemented using {@code DefaultExecuteResultHandler}. 70 | * 71 | * @throws Exception the test failed 72 | */ 73 | @Test 74 | public void testExec34Part2() throws Exception { 75 | 76 | final CommandLine cmdLine = new CommandLine(pingScript); 77 | cmdLine.addArgument("10"); // sleep 10 seconds 78 | 79 | final ExecuteWatchdog watchdog = new ExecuteWatchdog(5000); 80 | final DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler(); 81 | exec.setWatchdog(watchdog); 82 | exec.execute(cmdLine, handler); 83 | handler.waitFor(); 84 | assertTrue(handler.hasResult(), "Process has exited"); 85 | assertNotNull(handler.getException(), "Process was aborted"); 86 | assertTrue(watchdog.killedProcess(), "Watchdog should have killed the process"); 87 | assertFalse(watchdog.isWatching(), "Watchdog is no longer watching the process"); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/issues/Exec44Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.issues; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertFalse; 23 | import static org.junit.jupiter.api.Assertions.assertTrue; 24 | 25 | import java.io.File; 26 | 27 | import org.apache.commons.exec.CommandLine; 28 | import org.apache.commons.exec.DefaultExecuteResultHandler; 29 | import org.apache.commons.exec.DefaultExecutor; 30 | import org.apache.commons.exec.ExecuteWatchdog; 31 | import org.apache.commons.exec.Executor; 32 | import org.apache.commons.exec.TestUtil; 33 | import org.junit.jupiter.api.Test; 34 | 35 | /** 36 | * Test EXEC-44 (https://issues.apache.org/jira/browse/EXEC-44). 37 | */ 38 | public class Exec44Test { 39 | 40 | private final Executor exec = DefaultExecutor.builder().get(); 41 | private final File testDir = new File("src/test/scripts"); 42 | private final File foreverTestScript = TestUtil.resolveScriptFileForOS(testDir + "/forever"); 43 | 44 | /** 45 | * 46 | * Because the ExecuteWatchdog is the only way to destroy asynchronous processes, it should be possible to set it to an infinite timeout, for processes 47 | * which should not timeout, but manually destroyed under some circumstances. 48 | * 49 | * @throws Exception the test failed 50 | */ 51 | @Test 52 | public void testExec44() throws Exception { 53 | 54 | final CommandLine cl = new CommandLine(foreverTestScript); 55 | final DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); 56 | final ExecuteWatchdog watchdog = new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT); 57 | 58 | exec.setWatchdog(watchdog); 59 | exec.execute(cl, resultHandler); 60 | 61 | // wait for script to run 62 | Thread.sleep(5000); 63 | assertTrue(watchdog.isWatching(), "The watchdog is watching the process"); 64 | 65 | // terminate it 66 | watchdog.destroyProcess(); 67 | assertTrue(watchdog.killedProcess(), "The watchdog has killed the process"); 68 | assertFalse(watchdog.isWatching(), "The watchdog is no longer watching any process"); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/issues/Exec49Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.issues; 21 | 22 | import java.io.ByteArrayOutputStream; 23 | import java.io.PipedInputStream; 24 | import java.io.PipedOutputStream; 25 | import java.time.Duration; 26 | 27 | import org.apache.commons.exec.CommandLine; 28 | import org.apache.commons.exec.DefaultExecuteResultHandler; 29 | import org.apache.commons.exec.DefaultExecutor; 30 | import org.apache.commons.exec.Executor; 31 | import org.apache.commons.exec.PumpStreamHandler; 32 | import org.junit.jupiter.api.Test; 33 | import org.junit.jupiter.api.condition.DisabledOnOs; 34 | 35 | /** 36 | * Test EXEC-44 (https://issues.apache.org/jira/browse/EXEC-44). 37 | */ 38 | public class Exec49Test { 39 | 40 | private static final Duration WAIT = Duration.ofSeconds(10); 41 | private final Executor exec = DefaultExecutor.builder().get(); 42 | 43 | /** 44 | * The issue was detected when trying to capture stdout/stderr with a PipedOutputStream and then pass that to a PipedInputStream. The following code will 45 | * produce the error. The reason for the error is the PipedOutputStream is not being closed correctly, causing the PipedInputStream to break. 46 | * 47 | * @throws Exception the test failed 48 | */ 49 | @Test 50 | @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) 51 | public void testExec49Part1() throws Exception { 52 | final CommandLine cl = CommandLine.parse("/bin/ls"); 53 | cl.addArgument("/opt"); 54 | // redirect stdout/stderr to pipedOutputStream 55 | try (PipedOutputStream pipedOutputStream = new PipedOutputStream()) { 56 | final PumpStreamHandler psh = new PumpStreamHandler(pipedOutputStream); 57 | exec.setStreamHandler(psh); 58 | // start an asynchronous process to enable the main thread 59 | System.out.println("Preparing to execute process - commandLine=" + cl.toString()); 60 | final DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler(); 61 | exec.execute(cl, handler); 62 | System.out.println("Process spun off successfully - process=" + cl.getExecutable()); 63 | try (PipedInputStream pis = new PipedInputStream(pipedOutputStream)) { 64 | while (pis.read() >= 0) { 65 | // System.out.println("pis.available() " + pis.available()); 66 | // System.out.println("x " + x); 67 | } 68 | } 69 | handler.waitFor(WAIT); 70 | handler.getExitValue(); // will fail if process has not finished 71 | } 72 | } 73 | 74 | /** 75 | * The issue was detected when trying to capture stdout with a PipedOutputStream and then pass that to a PipedInputStream. The following code will produce 76 | * the error. The reason for the error is the PipedOutputStream is not being closed correctly, causing the PipedInputStream to break. 77 | * 78 | * @throws Exception the test failed 79 | */ 80 | @Test 81 | @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) 82 | public void testExec49Part2() throws Exception { 83 | final CommandLine cl = CommandLine.parse("/bin/ls"); 84 | cl.addArgument("/opt"); 85 | // redirect only stdout to pipedOutputStream 86 | try (PipedOutputStream pipedOutputStream = new PipedOutputStream()) { 87 | final PumpStreamHandler psh = new PumpStreamHandler(pipedOutputStream, new ByteArrayOutputStream()); 88 | exec.setStreamHandler(psh); 89 | // start an asynchronous process to enable the main thread 90 | System.out.println("Preparing to execute process - commandLine=" + cl.toString()); 91 | final DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler(); 92 | exec.execute(cl, handler); 93 | System.out.println("Process spun off successfully - process=" + cl.getExecutable()); 94 | try (PipedInputStream pis = new PipedInputStream(pipedOutputStream)) { 95 | while (pis.read() >= 0) { 96 | // System.out.println("pis.available() " + pis.available()); 97 | // System.out.println("x " + x); 98 | } 99 | } 100 | handler.waitFor(WAIT); 101 | handler.getExitValue(); // will fail if process has not finished 102 | } 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/issues/Exec57Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.issues; 21 | 22 | import java.io.IOException; 23 | import java.util.concurrent.TimeUnit; 24 | 25 | import org.apache.commons.exec.AbstractExecTest; 26 | import org.apache.commons.exec.CommandLine; 27 | import org.apache.commons.exec.DefaultExecutor; 28 | import org.apache.commons.exec.PumpStreamHandler; 29 | import org.junit.jupiter.api.Disabled; 30 | import org.junit.jupiter.api.Test; 31 | import org.junit.jupiter.api.Timeout; 32 | import org.junit.jupiter.api.condition.DisabledOnOs; 33 | 34 | /** 35 | * Test EXEC-57 (https://issues.apache.org/jira/browse/EXEC-57). 36 | */ 37 | public class Exec57Test extends AbstractExecTest { 38 | 39 | /** 40 | * DefaultExecutor.execute() does not return even if child process terminated - in this case the child process hangs because the grand children is connected 41 | * to stdout & stderr and is still running. As work-around a stop timeout is used for the PumpStreamHandler to ensure that the caller does not block forever 42 | * but if the stop timeout is exceeded an ExecuteException is thrown to notify the caller. But this case the threads are still around causing a resource 43 | * leak. 44 | * 45 | * @TODO [EXEC-57] Broken for macOS X & Linux 46 | */ 47 | @Disabled("Broken for Unix-based systems") 48 | @Test 49 | @Timeout(value = TEST_TIMEOUT, unit = TimeUnit.MILLISECONDS) 50 | public void testExecutionOfBackgroundProcess() throws IOException { 51 | 52 | final CommandLine cmdLine = new CommandLine("sh").addArgument("-c").addArgument("./src/test/scripts/issues/exec-57-nohup.sh", false); 53 | final DefaultExecutor executor = DefaultExecutor.builder().get(); 54 | final PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(System.out, System.err); 55 | 56 | executor.setStreamHandler(pumpStreamHandler); 57 | 58 | executor.execute(cmdLine); 59 | } 60 | 61 | /** 62 | * The same approach using a completely detached process works nicely on macOS X. 63 | * 64 | * @throws IOException 65 | */ 66 | @Test 67 | @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) 68 | @Timeout(value = TEST_TIMEOUT, unit = TimeUnit.MILLISECONDS) 69 | public void testExecutionOfDetachedProcess() throws IOException { 70 | final CommandLine cmdLine = new CommandLine("sh").addArgument("-c").addArgument("./src/test/scripts/issues/exec-57-detached.sh", false); 71 | final DefaultExecutor executor = DefaultExecutor.builder().get(); 72 | final PumpStreamHandler pumpStreamHandler = new PumpStreamHandler(System.out, System.err); 73 | 74 | executor.setStreamHandler(pumpStreamHandler); 75 | 76 | executor.execute(cmdLine); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/issues/Exec60Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.issues; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertTrue; 23 | 24 | import java.io.File; 25 | 26 | import org.apache.commons.exec.AbstractExecTest; 27 | import org.apache.commons.exec.CommandLine; 28 | import org.apache.commons.exec.DefaultExecutor; 29 | import org.apache.commons.exec.ExecuteException; 30 | import org.apache.commons.exec.ExecuteWatchdog; 31 | import org.apache.commons.exec.Executor; 32 | import org.junit.jupiter.api.Disabled; 33 | import org.junit.jupiter.api.Test; 34 | 35 | /** 36 | * Test EXEC-60 (https://issues.apache.org/jira/browse/EXEC-60). 37 | */ 38 | public class Exec60Test extends AbstractExecTest { 39 | 40 | private final Executor exec = DefaultExecutor.builder().get(); 41 | private final File pingScript = resolveTestScript("ping"); 42 | 43 | /** 44 | * Possible deadlock when a process is terminating at the same time its timing out. Please note that a successful test is no proof that the issues was 45 | * indeed fixed. 46 | */ 47 | @Disabled("The test is fragile and might fail out of the blue") 48 | @Test 49 | public void testExec60() throws Exception { 50 | 51 | final int start = 0; 52 | final int seconds = 1; 53 | final int offsetMultiplier = 1; 54 | final int maxRetries = 180; 55 | int processTerminatedCounter = 0; 56 | int watchdogKilledProcessCounter = 0; 57 | final CommandLine cmdLine = new CommandLine(pingScript); 58 | cmdLine.addArgument(Integer.toString(seconds + 1)); // need to add "1" to wait the requested number of seconds 59 | 60 | final long startTime = System.currentTimeMillis(); 61 | for (int offset = start; offset <= maxRetries; offset++) { 62 | // wait progressively longer for process to complete 63 | // tricky to get this test right. We want to try and catch the process while it is terminating, 64 | // so we increase the timeout gradually until the test terminates normally. 65 | // However if the increase is too gradual, we never wait long enough for any test to exit normally 66 | final ExecuteWatchdog watchdog = new ExecuteWatchdog(seconds * 1000 + offset * offsetMultiplier); 67 | exec.setWatchdog(watchdog); 68 | try { 69 | exec.execute(cmdLine); 70 | processTerminatedCounter++; 71 | // System.out.println(offset + ": process has terminated: " + watchdog.killedProcess()); 72 | if (processTerminatedCounter > 5) { 73 | break; 74 | } 75 | } catch (final ExecuteException ex) { 76 | // System.out.println(offset + ": process was killed: " + watchdog.killedProcess()); 77 | assertTrue(watchdog.killedProcess(), "Watchdog killed the process"); 78 | watchdogKilledProcessCounter++; 79 | } 80 | } 81 | 82 | final long avg = (System.currentTimeMillis() - startTime) / (watchdogKilledProcessCounter + processTerminatedCounter); 83 | System.out.println("Processes terminated: " + processTerminatedCounter + " killed: " + watchdogKilledProcessCounter + " Multiplier: " + offsetMultiplier 84 | + " MaxRetries: " + maxRetries + " Elapsed (avg ms): " + avg); 85 | assertTrue(processTerminatedCounter > 0, "Not a single process terminated on its own"); 86 | assertTrue(watchdogKilledProcessCounter > 0, "Not a single process was killed by the watch dog"); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/issues/Exec62Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.issues; 21 | 22 | import java.io.File; 23 | import java.io.OutputStream; 24 | import java.nio.file.Files; 25 | import java.nio.file.Path; 26 | import java.util.concurrent.TimeUnit; 27 | import java.util.concurrent.TimeoutException; 28 | 29 | import org.apache.commons.exec.CommandLine; 30 | import org.apache.commons.exec.DefaultExecutor; 31 | import org.apache.commons.exec.ExecuteWatchdog; 32 | import org.apache.commons.exec.PumpStreamHandler; 33 | import org.apache.commons.exec.TestUtil; 34 | import org.junit.jupiter.api.AfterEach; 35 | import org.junit.jupiter.api.BeforeEach; 36 | import org.junit.jupiter.api.Disabled; 37 | import org.junit.jupiter.api.Test; 38 | import org.junit.jupiter.api.Timeout; 39 | import org.junit.jupiter.api.condition.DisabledOnOs; 40 | 41 | /** 42 | * @see EXEC-62 43 | */ 44 | public class Exec62Test { 45 | private Path outputFile; 46 | 47 | private void execute(final String scriptName) throws Exception { 48 | final ExecuteWatchdog watchdog = new ExecuteWatchdog(4000); 49 | final CommandLine commandLine = new CommandLine("/bin/sh"); 50 | final File testScript = TestUtil.resolveScriptFileForOS("./src/test/scripts/issues/" + scriptName); 51 | 52 | commandLine.addArgument(testScript.getAbsolutePath()); 53 | 54 | final DefaultExecutor executor = DefaultExecutor.builder().get(); 55 | executor.setExitValues(null); // ignore exit values 56 | executor.setWatchdog(watchdog); 57 | 58 | try (OutputStream fos = Files.newOutputStream(outputFile)) { 59 | final PumpStreamHandler streamHandler = new PumpStreamHandler(fos); 60 | executor.setStreamHandler(streamHandler); 61 | executor.execute(commandLine); 62 | 63 | if (watchdog.killedProcess()) { 64 | throw new TimeoutException(String.format("Transcode process was killed on timeout %1$s ms, command line %2$s", 4000, commandLine.toString())); 65 | } 66 | } 67 | } 68 | 69 | @BeforeEach 70 | public void setUp() throws Exception { 71 | outputFile = Files.createTempFile("foo", ".log"); 72 | } 73 | 74 | @AfterEach 75 | public void tearDown() throws Exception { 76 | Files.delete(outputFile); 77 | } 78 | 79 | @Disabled("Test behaves differently between macOS X and Linux - don't know why") 80 | @Test 81 | @DisabledOnOs(org.junit.jupiter.api.condition.OS.WINDOWS) 82 | @Timeout(value = 10, unit = TimeUnit.SECONDS) 83 | public void testMe() throws Exception { 84 | execute("exec-62"); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/launcher/AbstractCommandLauncherTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertFalse; 23 | import static org.junit.jupiter.api.Assertions.assertTrue; 24 | 25 | import org.junit.jupiter.api.Test; 26 | 27 | abstract class AbstractCommandLauncherTest { 28 | 29 | abstract T createCommandLauncher(); 30 | 31 | @Test 32 | public void testIsFailure() throws Exception { 33 | final T commandLauncher = createCommandLauncher(); 34 | assertTrue(commandLauncher.isFailure(2)); 35 | assertTrue(commandLauncher.isFailure(1)); 36 | } 37 | 38 | @Test 39 | public void testIsFailureZero() throws Exception { 40 | assertFalse(createCommandLauncher().isFailure(0)); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/launcher/CommandLauncherFactoryTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertNotNull; 23 | 24 | import org.junit.jupiter.api.Test; 25 | 26 | /** 27 | * Tests {@link CommandLauncherFactory}. 28 | */ 29 | public class CommandLauncherFactoryTest { 30 | 31 | @Test 32 | public void testCreateVMLauncher() throws Exception { 33 | assertNotNull(CommandLauncherFactory.createVMLauncher()); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/launcher/CommandLauncherImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | import java.io.File; 23 | import java.io.IOException; 24 | import java.util.Map; 25 | 26 | import org.apache.commons.exec.CommandLine; 27 | 28 | public class CommandLauncherImplTest extends AbstractCommandLauncherTest { 29 | 30 | static class CommandLauncherImplFixture extends CommandLauncherImpl { 31 | 32 | @Override 33 | public Process exec(final CommandLine cmd, final Map env, final File workingDir) throws IOException { 34 | return null; 35 | } 36 | 37 | } 38 | 39 | @Override 40 | CommandLauncherImpl createCommandLauncher() { 41 | return new CommandLauncherImplFixture(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/launcher/Java13CommandLauncherTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | public class Java13CommandLauncherTest extends AbstractCommandLauncherTest { 23 | 24 | @Override 25 | Java13CommandLauncher createCommandLauncher() { 26 | return new Java13CommandLauncher(); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/launcher/OS2CommandLauncherTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | public class OS2CommandLauncherTest extends AbstractCommandLauncherTest { 23 | 24 | @Override 25 | OS2CommandLauncher createCommandLauncher() { 26 | return new OS2CommandLauncher(CommandLauncherFactory.createVMLauncher()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/launcher/VmsCommandLauncherTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertFalse; 23 | import static org.junit.jupiter.api.Assertions.assertNotNull; 24 | import static org.junit.jupiter.api.Assertions.assertTrue; 25 | 26 | import java.io.IOException; 27 | import java.util.HashMap; 28 | import java.util.Map; 29 | 30 | import org.apache.commons.exec.CommandLine; 31 | import org.junit.jupiter.api.Test; 32 | 33 | public class VmsCommandLauncherTest extends AbstractCommandLauncherTest { 34 | 35 | @Override 36 | VmsCommandLauncher createCommandLauncher() { 37 | return new VmsCommandLauncher(); 38 | } 39 | 40 | @Test 41 | public void testCreateCommandFile() throws IOException { 42 | final VmsCommandLauncher commandLauncher = createCommandLauncher(); 43 | final CommandLine cl = CommandLine.parse("a b \"c d\""); 44 | assertNotNull(commandLauncher.createCommandFile(cl, null)); 45 | final Map env = new HashMap<>(); 46 | assertNotNull(commandLauncher.createCommandFile(cl, env)); 47 | env.put("EnvKey", "EnvValue"); 48 | assertNotNull(commandLauncher.createCommandFile(cl, env)); 49 | 50 | } 51 | 52 | @Override 53 | @Test 54 | public void testIsFailure() throws Exception { 55 | final CommandLauncher commandLauncher = createCommandLauncher(); 56 | assertTrue(commandLauncher.isFailure(2)); 57 | assertFalse(commandLauncher.isFailure(1)); 58 | } 59 | 60 | @Override 61 | @Test 62 | public void testIsFailureZero() throws Exception { 63 | assertTrue(createCommandLauncher().isFailure(0)); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/launcher/WinNTCommandLauncherTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.launcher; 21 | 22 | public class WinNTCommandLauncherTest extends AbstractCommandLauncherTest { 23 | 24 | @Override 25 | WinNTCommandLauncher createCommandLauncher() { 26 | return new WinNTCommandLauncher(CommandLauncherFactory.createVMLauncher()); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/util/MapUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.util; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertEquals; 23 | import static org.junit.jupiter.api.Assertions.assertTrue; 24 | 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | 28 | import org.apache.commons.exec.environment.EnvironmentUtils; 29 | import org.junit.jupiter.api.Test; 30 | 31 | /** 32 | */ 33 | public class MapUtilTest { 34 | 35 | /** 36 | * Test copying of map 37 | */ 38 | @Test 39 | public void testCopyMap() throws Exception { 40 | final Map procEnvironment = new HashMap<>(); 41 | procEnvironment.put("JAVA_HOME", "/usr/opt/java"); 42 | final Map result = MapUtils.copy(procEnvironment); 43 | assertEquals(1, result.size()); 44 | assertEquals(1, procEnvironment.size()); 45 | assertEquals("/usr/opt/java", result.get("JAVA_HOME")); 46 | result.remove("JAVA_HOME"); 47 | assertTrue(result.isEmpty()); 48 | assertEquals(1, procEnvironment.size()); 49 | } 50 | 51 | /** 52 | * Test merging of maps 53 | */ 54 | @Test 55 | public void testMergeMap() throws Exception { 56 | final Map procEnvironment = EnvironmentUtils.getProcEnvironment(); 57 | final Map applicationEnvironment = new HashMap<>(); 58 | applicationEnvironment.put("appMainClass", "foo.bar.Main"); 59 | final Map result = MapUtils.merge(procEnvironment, applicationEnvironment); 60 | assertEquals(procEnvironment.size() + applicationEnvironment.size(), result.size()); 61 | assertEquals("foo.bar.Main", result.get("appMainClass")); 62 | } 63 | 64 | /** 65 | * Test prefixing of map 66 | */ 67 | @Test 68 | public void testPrefixMap() throws Exception { 69 | final Map procEnvironment = new HashMap<>(); 70 | procEnvironment.put("JAVA_HOME", "/usr/opt/java"); 71 | final Map result = MapUtils.prefix(procEnvironment, "env"); 72 | assertEquals(procEnvironment.size(), result.size()); 73 | assertEquals("/usr/opt/java", result.get("env.JAVA_HOME")); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/test/java/org/apache/commons/exec/util/StringUtilTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * https://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | package org.apache.commons.exec.util; 21 | 22 | import static org.junit.jupiter.api.Assertions.assertEquals; 23 | import static org.junit.jupiter.api.Assertions.fail; 24 | 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | 28 | import org.junit.jupiter.api.Test; 29 | 30 | /** 31 | */ 32 | public class StringUtilTest { 33 | /** 34 | * Test a default string substitution, e.g. all placeholders are expanded. 35 | */ 36 | @Test 37 | public void testDefaultStringSubstitution() throws Exception { 38 | final Map vars = new HashMap<>(); 39 | vars.put("foo", "FOO"); 40 | vars.put("bar", "BAR"); 41 | 42 | assertEquals("This is a FOO & BAR test", StringUtils.stringSubstitution("This is a ${foo} & ${bar} test", vars, true).toString()); 43 | assertEquals("This is a FOO & BAR test", StringUtils.stringSubstitution("This is a ${foo} & ${bar} test", vars, false).toString()); 44 | } 45 | 46 | /** 47 | * Test a erroneous template. 48 | */ 49 | @Test 50 | public void testErroneousTemplate() throws Exception { 51 | final Map vars = new HashMap<>(); 52 | vars.put("foo", "FOO"); 53 | 54 | assertEquals("This is a FOO & ${}} test", StringUtils.stringSubstitution("This is a ${foo} & ${}} test", vars, true).toString()); 55 | } 56 | 57 | /** 58 | * Test an incomplete string substitution where not all placeholders are expanded. 59 | */ 60 | @Test 61 | public void testIncompleteSubstitution() throws Exception { 62 | 63 | final Map vars = new HashMap<>(); 64 | vars.put("foo", "FOO"); 65 | 66 | assertEquals("This is a FOO & ${bar} test", StringUtils.stringSubstitution("This is a ${foo} & ${bar} test", vars, true).toString()); 67 | 68 | try { 69 | StringUtils.stringSubstitution("This is a ${foo} & ${bar} test", vars, false).toString(); 70 | fail(); 71 | } catch (final RuntimeException e) { 72 | // nothing to do 73 | } 74 | } 75 | 76 | /** 77 | * Test no string substitution 78 | */ 79 | @Test 80 | public void testNoStringSubstitution() throws Exception { 81 | final Map vars = new HashMap<>(); 82 | vars.put("foo", "FOO"); 83 | vars.put("bar", "BAR"); 84 | 85 | assertEquals("This is a FOO & BAR test", StringUtils.stringSubstitution("This is a FOO & BAR test", vars, true).toString()); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/test/scripts/acrord32.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Licensed to the Apache Software Foundation (ASF) under one or more 4 | REM contributor license agreements. See the NOTICE file distributed with 5 | REM this work for additional information regarding copyright ownership. 6 | REM The ASF licenses this file to You under the Apache License, Version 2.0 7 | REM (the "License"); you may not use this file except in compliance with 8 | REM the License. You may obtain a copy of the License at 9 | REM 10 | REM https://www.apache.org/licenses/LICENSE-2.0 11 | REM 12 | REM Unless required by applicable law or agreed to in writing, software 13 | REM distributed under the License is distributed on an "AS IS" BASIS, 14 | REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | REM See the License for the specific language governing permissions and 16 | REM limitations under the License. 17 | 18 | echo "[acrord32] Printing the following document : '%3'" 19 | ping -n 10 -w 1000 127.0.0.1 > nul 20 | echo "[acrord32] Finished printing" 21 | exit 1 22 | -------------------------------------------------------------------------------- /src/test/scripts/acrord32.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | # Simulate printing a PDF document 21 | 22 | echo "[acrord32] Printing the following document : $3" 23 | for i in {1..10} 24 | do 25 | sleep 1 26 | done 27 | echo "[acrord32] Finished printing" 28 | exit 1 29 | 30 | -------------------------------------------------------------------------------- /src/test/scripts/environment.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Little batch file to run nearly foerver 4 | REM see https://malektips.com/dos0017.html 5 | REM 6 | REM Licensed to the Apache Software Foundation (ASF) under one or more 7 | REM contributor license agreements. See the NOTICE file distributed with 8 | REM this work for additional information regarding copyright ownership. 9 | REM The ASF licenses this file to You under the Apache License, Version 2.0 10 | REM (the "License"); you may not use this file except in compliance with 11 | REM the License. You may obtain a copy of the License at 12 | REM 13 | REM https://www.apache.org/licenses/LICENSE-2.0 14 | REM 15 | REM Unless required by applicable law or agreed to in writing, software 16 | REM distributed under the License is distributed on an "AS IS" BASIS, 17 | REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | REM See the License for the specific language governing permissions and 19 | REM limitations under the License. 20 | 21 | REM print the environment variables 22 | set -------------------------------------------------------------------------------- /src/test/scripts/environment.dcl: -------------------------------------------------------------------------------- 1 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2 | $! 3 | $! Licensed to the Apache Software Foundation (ASF) under one or more 4 | $! contributor license agreements. See the NOTICE file distributed with 5 | $! this work for additional information regarding copyright ownership. 6 | $! The ASF licenses this file to You under the Apache License, Version 2.0 7 | $! (the "License"); you may not use this file except in compliance with 8 | $! the License. You may obtain a copy of the License at 9 | $! 10 | $! https://www.apache.org/licenses/LICENSE-2.0 11 | $! 12 | $! Unless required by applicable law or agreed to in writing, software 13 | $! distributed under the License is distributed on an "AS IS" BASIS, 14 | $! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | $! See the License for the specific language governing permissions and 16 | $! limitations under the License. 17 | $! 18 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 19 | $! 20 | $! print the "environment" variables 21 | $! 22 | $ show symbol * -------------------------------------------------------------------------------- /src/test/scripts/environment.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | # print the environment variables 21 | env -------------------------------------------------------------------------------- /src/test/scripts/error.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Licensed to the Apache Software Foundation (ASF) under one or more 4 | REM contributor license agreements. See the NOTICE file distributed with 5 | REM this work for additional information regarding copyright ownership. 6 | REM The ASF licenses this file to You under the Apache License, Version 2.0 7 | REM (the "License"); you may not use this file except in compliance with 8 | REM the License. You may obtain a copy of the License at 9 | REM 10 | REM https://www.apache.org/licenses/LICENSE-2.0 11 | REM 12 | REM Unless required by applicable law or agreed to in writing, software 13 | REM distributed under the License is distributed on an "AS IS" BASIS, 14 | REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | REM See the License for the specific language governing permissions and 16 | REM limitations under the License. 17 | 18 | REM This test script will return an error exit code 19 | 20 | @echo FOO.%TEST_ENV_VAR%.%1 21 | 22 | EXIT 1 23 | -------------------------------------------------------------------------------- /src/test/scripts/error.dcl: -------------------------------------------------------------------------------- 1 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2 | $! 3 | $! Licensed to the Apache Software Foundation (ASF) under one or more 4 | $! contributor license agreements. See the NOTICE file distributed with 5 | $! this work for additional information regarding copyright ownership. 6 | $! The ASF licenses this file to You under the Apache License, Version 2.0 7 | $! (the "License"); you may not use this file except in compliance with 8 | $! the License. You may obtain a copy of the License at 9 | $! 10 | $! https://www.apache.org/licenses/LICENSE-2.0 11 | $! 12 | $! Unless required by applicable law or agreed to in writing, software 13 | $! distributed under the License is distributed on an "AS IS" BASIS, 14 | $! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | $! See the License for the specific language governing permissions and 16 | $! limitations under the License. 17 | $! 18 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 19 | $! 20 | $! do something and return an error result code 21 | $! 22 | $ ENV_VAR=f$trnlnm("TEST_ENV_VAR") 23 | $ write sys$output "FOO.''ENV_VAR'.''P1'" 24 | $! 25 | $ exit %x10000002 ! this is an Error, but does not print a message -------------------------------------------------------------------------------- /src/test/scripts/error.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | # 20 | 21 | # do something and return en error result code 22 | 23 | echo FOO.$TEST_ENV_VAR.$1 24 | exit 1 25 | -------------------------------------------------------------------------------- /src/test/scripts/forever.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Little batch file to run nearly foerver 4 | REM see https://malektips.com/dos0017.html 5 | REM 6 | REM Licensed to the Apache Software Foundation (ASF) under one or more 7 | REM contributor license agreements. See the NOTICE file distributed with 8 | REM this work for additional information regarding copyright ownership. 9 | REM The ASF licenses this file to You under the Apache License, Version 2.0 10 | REM (the "License"); you may not use this file except in compliance with 11 | REM the License. You may obtain a copy of the License at 12 | REM 13 | REM https://www.apache.org/licenses/LICENSE-2.0 14 | REM 15 | REM Unless required by applicable law or agreed to in writing, software 16 | REM distributed under the License is distributed on an "AS IS" BASIS, 17 | REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | REM See the License for the specific language governing permissions and 19 | REM limitations under the License. 20 | 21 | REM run an infinite loop so the script will never ever terminate on its behalf 22 | REM and append a '.' after each second 23 | 24 | :LOOP 25 | ECHO . >> .\target\forever.txt 26 | @ping 127.0.0.1 -n 2 -w 1000 > nul 27 | GOTO LOOP -------------------------------------------------------------------------------- /src/test/scripts/forever.dcl: -------------------------------------------------------------------------------- 1 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2 | $! 3 | $! Licensed to the Apache Software Foundation (ASF) under one or more 4 | $! contributor license agreements. See the NOTICE file distributed with 5 | $! this work for additional information regarding copyright ownership. 6 | $! The ASF licenses this file to You under the Apache License, Version 2.0 7 | $! (the "License"); you may not use this file except in compliance with 8 | $! the License. You may obtain a copy of the License at 9 | $! 10 | $! https://www.apache.org/licenses/LICENSE-2.0 11 | $! 12 | $! Unless required by applicable law or agreed to in writing, software 13 | $! distributed under the License is distributed on an "AS IS" BASIS, 14 | $! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | $! See the License for the specific language governing permissions and 16 | $! limitations under the License. 17 | $! 18 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 19 | $! 20 | $! run an infinite loop so the script will never ever terminate 21 | $! 22 | $! Suppress timeout warning 23 | $ l_msg=f$environment("MESSAGE") 24 | $ SET MESSAGE /NOFACILITY /NOIDENTIFICATION /NOSEVERITY /NOTEXT 25 | $! 26 | $ SET NOON 27 | $ ON CONTROL_Y THEN GOTO DONE 28 | $ close/nolog OUT 29 | $ open/write OUT [.target]forever.txt ! create the output file 30 | $LOOP: 31 | $ write OUT "." 32 | $ read /prompt="."/time_out=1 sys$command dummy 33 | $ GOTO LOOP 34 | $! 35 | $DONE: 36 | $ close/nolog OUT 37 | $! Restore message settings 38 | $ SET MESSAGE 'l_msg' -------------------------------------------------------------------------------- /src/test/scripts/forever.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | # run an infinite loop so the script will never ever terminate on its behalf 21 | # and append a '.' after each second 22 | 23 | while test "notempty" 24 | do 25 | sleep 1 26 | echo '.\c' >> ./target/forever.txt 27 | done -------------------------------------------------------------------------------- /src/test/scripts/issues/exec-57-detached.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | # Create a background process where the child is completely detached 21 | 22 | echo "invoker.sh -- going to start daemon process" 23 | cd ./target 24 | nohup sleep 60 1>/dev/null 2>/dev/null 0&2 & 23 | sleep 15 -------------------------------------------------------------------------------- /src/test/scripts/issues/exec-65.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | # force re-authentication 21 | sudo -K 22 | 23 | # run the "ls" command as "root" user but prompt for password 24 | sudo -S -u root ls 25 | -------------------------------------------------------------------------------- /src/test/scripts/ping.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Little batch file to pause for a number of seconds 4 | REM see https://malektips.com/dos0017.html 5 | REM 6 | REM Licensed to the Apache Software Foundation (ASF) under one or more 7 | REM contributor license agreements. See the NOTICE file distributed with 8 | REM this work for additional information regarding copyright ownership. 9 | REM The ASF licenses this file to You under the Apache License, Version 2.0 10 | REM (the "License"); you may not use this file except in compliance with 11 | REM the License. You may obtain a copy of the License at 12 | REM 13 | REM https://www.apache.org/licenses/LICENSE-2.0 14 | REM 15 | REM Unless required by applicable law or agreed to in writing, software 16 | REM distributed under the License is distributed on an "AS IS" BASIS, 17 | REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | REM See the License for the specific language governing permissions and 19 | REM limitations under the License. 20 | 21 | REM ping is started as subprocess which runs '%1' seconds 22 | 23 | echo "[ping.bat] Blocking for %1 seconds ..." 24 | ping.exe -n %1 -w 1000 127.0.0.1 > nul -------------------------------------------------------------------------------- /src/test/scripts/ping.dcl: -------------------------------------------------------------------------------- 1 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2 | $! 3 | $! Licensed to the Apache Software Foundation (ASF) under one or more 4 | $! contributor license agreements. See the NOTICE file distributed with 5 | $! this work for additional information regarding copyright ownership. 6 | $! The ASF licenses this file to You under the Apache License, Version 2.0 7 | $! (the "License"); you may not use this file except in compliance with 8 | $! the License. You may obtain a copy of the License at 9 | $! 10 | $! https://www.apache.org/licenses/LICENSE-2.0 11 | $! 12 | $! Unless required by applicable law or agreed to in writing, software 13 | $! distributed under the License is distributed on an "AS IS" BASIS, 14 | $! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | $! See the License for the specific language governing permissions and 16 | $! limitations under the License. 17 | $! 18 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 19 | $! 20 | $! ping is started as subprocess which runs for 'P1' seconds 21 | $! 22 | $ write sys$output "[ping.dcl] Blocking for ''P1' seconds ..." 23 | $ tcpip ping 127.0.0.1 /number_packets='P1 /wait=1 -------------------------------------------------------------------------------- /src/test/scripts/ping.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | # ping is started as subprocess which runs for '$1' seconds 21 | 22 | echo "[ping.sh] Blocking for $1 seconds ..." 23 | # see EXEC-52 - option must appear after the hostname! 24 | if test "$(uname -s)" = "HP-UX" 25 | then 26 | ping 127.0.0.1 -n $1 27 | else 28 | ping -c $1 127.0.0.1 29 | fi 30 | -------------------------------------------------------------------------------- /src/test/scripts/printargs.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Licensed to the Apache Software Foundation (ASF) under one or more 4 | REM contributor license agreements. See the NOTICE file distributed with 5 | REM this work for additional information regarding copyright ownership. 6 | REM The ASF licenses this file to You under the Apache License, Version 2.0 7 | REM (the "License"); you may not use this file except in compliance with 8 | REM the License. You may obtain a copy of the License at 9 | REM 10 | REM https://www.apache.org/licenses/LICENSE-2.0 11 | REM 12 | REM Unless required by applicable law or agreed to in writing, software 13 | REM distributed under the License is distributed on an "AS IS" BASIS, 14 | REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | REM See the License for the specific language governing permissions and 16 | REM limitations under the License. 17 | 18 | REM checking for emptiness was tricky - see https://www.robvanderwoude.com/parameters.php 19 | 20 | :Loop 21 | IF [%1]==[] GOTO Continue 22 | @ECHO "%1" 23 | SHIFT 24 | GOTO Loop 25 | :Continue -------------------------------------------------------------------------------- /src/test/scripts/printargs.dcl: -------------------------------------------------------------------------------- 1 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2 | $! 3 | $! Licensed to the Apache Software Foundation (ASF) under one or more 4 | $! contributor license agreements. See the NOTICE file distributed with 5 | $! this work for additional information regarding copyright ownership. 6 | $! The ASF licenses this file to You under the Apache License, Version 2.0 7 | $! (the "License"); you may not use this file except in compliance with 8 | $! the License. You may obtain a copy of the License at 9 | $! 10 | $! https://www.apache.org/licenses/LICENSE-2.0 11 | $! 12 | $! Unless required by applicable law or agreed to in writing, software 13 | $! distributed under the License is distributed on an "AS IS" BASIS, 14 | $! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | $! See the License for the specific language governing permissions and 16 | $! limitations under the License. 17 | $! 18 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 19 | $! 20 | $! Print arguments 21 | $! 22 | $! Crude, but effective. Works even if argument contains un-doubled double-quotes 23 | $ if f$length(P1) .gt. 0 then write sys$output P1 24 | $ if f$length(P2) .gt. 0 then write sys$output P2 25 | $ if f$length(P3) .gt. 0 then write sys$output P3 26 | $ if f$length(P4) .gt. 0 then write sys$output P4 27 | $ if f$length(P5) .gt. 0 then write sys$output P5 28 | $ if f$length(P6) .gt. 0 then write sys$output P6 29 | $ if f$length(P7) .gt. 0 then write sys$output P7 30 | $ if f$length(P8) .gt. 0 then write sys$output P8 -------------------------------------------------------------------------------- /src/test/scripts/printargs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | # Helper script to print out the command line arguments 21 | 22 | while [ $# -gt 0 ] 23 | do 24 | echo "$1" 25 | shift 26 | done 27 | 28 | -------------------------------------------------------------------------------- /src/test/scripts/redirect.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | # read from stdin and output to stdout 21 | 22 | while read myline 23 | do 24 | echo "stdout: $myline" 25 | done 26 | 27 | echo 1>&2 "stderr: Finished reading from stdin" 28 | 29 | exit 0 30 | 31 | -------------------------------------------------------------------------------- /src/test/scripts/sleep.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM 4 | REM Licensed to the Apache Software Foundation (ASF) under one or more 5 | REM contributor license agreements. See the NOTICE file distributed with 6 | REM this work for additional information regarding copyright ownership. 7 | REM The ASF licenses this file to You under the Apache License, Version 2.0 8 | REM (the "License"); you may not use this file except in compliance with 9 | REM the License. You may obtain a copy of the License at 10 | REM 11 | REM https://www.apache.org/licenses/LICENSE-2.0 12 | REM 13 | REM Unless required by applicable law or agreed to in writing, software 14 | REM distributed under the License is distributed on an "AS IS" BASIS, 15 | REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | REM See the License for the specific language governing permissions and 17 | REM limitations under the License. 18 | 19 | @ping -n 60 localhost> nul 20 | -------------------------------------------------------------------------------- /src/test/scripts/sleep.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | sleep 60 -------------------------------------------------------------------------------- /src/test/scripts/standalone.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | mkdir target/ 21 | cat pom.xml | gzip> ./target/mybackup.gz 22 | -------------------------------------------------------------------------------- /src/test/scripts/stdin.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Licensed to the Apache Software Foundation (ASF) under one or more 4 | REM contributor license agreements. See the NOTICE file distributed with 5 | REM this work for additional information regarding copyright ownership. 6 | REM The ASF licenses this file to You under the Apache License, Version 2.0 7 | REM (the "License"); you may not use this file except in compliance with 8 | REM the License. You may obtain a copy of the License at 9 | REM 10 | REM https://www.apache.org/licenses/LICENSE-2.0 11 | REM 12 | REM Unless required by applicable law or agreed to in writing, software 13 | REM distributed under the License is distributed on an "AS IS" BASIS, 14 | REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | REM See the License for the specific language governing permissions and 16 | REM limitations under the License. 17 | 18 | set /p answer=What's your name? : 19 | echo Hello %answer%! -------------------------------------------------------------------------------- /src/test/scripts/stdin.dcl: -------------------------------------------------------------------------------- 1 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2 | $! 3 | $! Licensed to the Apache Software Foundation (ASF) under one or more 4 | $! contributor license agreements. See the NOTICE file distributed with 5 | $! this work for additional information regarding copyright ownership. 6 | $! The ASF licenses this file to You under the Apache License, Version 2.0 7 | $! (the "License"); you may not use this file except in compliance with 8 | $! the License. You may obtain a copy of the License at 9 | $! 10 | $! https://www.apache.org/licenses/LICENSE-2.0 11 | $! 12 | $! Unless required by applicable law or agreed to in writing, software 13 | $! distributed under the License is distributed on an "AS IS" BASIS, 14 | $! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | $! See the License for the specific language governing permissions and 16 | $! limitations under the License. 17 | $! 18 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 19 | $! 20 | $! Read input and display it 21 | $! 22 | $ read /prompt="What's your name? : " sys$command answer 23 | $ write sys$output "Hello ''answer'!" -------------------------------------------------------------------------------- /src/test/scripts/stdin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | echo "What's your name? : " 21 | read answer 22 | echo "Hello $answer!" 23 | 24 | -------------------------------------------------------------------------------- /src/test/scripts/test.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM 4 | REM Licensed to the Apache Software Foundation (ASF) under one or more 5 | REM contributor license agreements. See the NOTICE file distributed with 6 | REM this work for additional information regarding copyright ownership. 7 | REM The ASF licenses this file to You under the Apache License, Version 2.0 8 | REM (the "License"); you may not use this file except in compliance with 9 | REM the License. You may obtain a copy of the License at 10 | REM 11 | REM https://www.apache.org/licenses/LICENSE-2.0 12 | REM 13 | REM Unless required by applicable law or agreed to in writing, software 14 | REM distributed under the License is distributed on an "AS IS" BASIS, 15 | REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | REM See the License for the specific language governing permissions and 17 | REM limitations under the License. 18 | REM 19 | REM 20 | 21 | REM print the given environment variable and command line parameter 22 | REM since this is verified by the regression test 23 | 24 | @ECHO FOO.%TEST_ENV_VAR%.%1 25 | -------------------------------------------------------------------------------- /src/test/scripts/test.dcl: -------------------------------------------------------------------------------- 1 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 2 | $! 3 | $! Licensed to the Apache Software Foundation (ASF) under one or more 4 | $! contributor license agreements. See the NOTICE file distributed with 5 | $! this work for additional information regarding copyright ownership. 6 | $! The ASF licenses this file to You under the Apache License, Version 2.0 7 | $! (the "License"); you may not use this file except in compliance with 8 | $! the License. You may obtain a copy of the License at 9 | $! 10 | $! https://www.apache.org/licenses/LICENSE-2.0 11 | $! 12 | $! Unless required by applicable law or agreed to in writing, software 13 | $! distributed under the License is distributed on an "AS IS" BASIS, 14 | $! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | $! See the License for the specific language governing permissions and 16 | $! limitations under the License. 17 | $! 18 | $!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 19 | $! 20 | $! print the given environment variable and command line parameter 21 | $! since this is verified by the regression test 22 | $! 23 | $ write sys$output "FOO.''TEST_ENV_VAR'.''P1'" 24 | $! 25 | $ exit 1 ! normal exit -------------------------------------------------------------------------------- /src/test/scripts/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Licensed to the Apache Software Foundation (ASF) under one or more 5 | # contributor license agreements. See the NOTICE file distributed with 6 | # this work for additional information regarding copyright ownership. 7 | # The ASF licenses this file to You under the Apache License, Version 2.0 8 | # (the "License"); you may not use this file except in compliance with 9 | # the License. You may obtain a copy of the License at 10 | # 11 | # https://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | # print the given environment variable and command line parameter 21 | # since this is verified by the regression test 22 | 23 | echo FOO.$TEST_ENV_VAR.$1 24 | --------------------------------------------------------------------------------