Results 1 to 6 of 6

Thread: SystemCommandTasklet usage

  1. #1
    Join Date
    Nov 2009
    Location
    India
    Posts
    15

    Default SystemCommandTasklet usage

    Hi ,

    I have requirement to encrypt file using third party tool/commands.

    I want to use SystemCommandTasklet to execute third party commands like pgp -v

    Job Configuration:

    <bean id="commandLine" class="org.springframework.batch.core.step.tasklet .SystemCommandTasklet">
    <property name="command" value="pgp -v" />
    <property name="timeout" value="5000" />

    </bean>

    Any suggestions on this approach are highly appreciated.

    Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Location
    India
    Posts
    15

    Default

    Can someone give me an idea(s) on this?

  3. #3
    Join Date
    Oct 2009
    Location
    San Francisco CA
    Posts
    42

    Default

    Your approach looks correct. Do note that these commands usually won't return the error code properly, so you need to figure out a way to check if the job ran successfully.

    I would add another property to the tasklet,

    Code:
    <beans:property name="systemProcessExitCodeMapper">
        <beans:bean class="org.springframework.batch.core.step.tasklet.SimpleSystemProcessExitCodeMapper"/>
    </beans:property>

  4. #4
    Join Date
    Nov 2009
    Location
    India
    Posts
    15

    Default

    Thank you for your replay.

    I tried to execute system command ex: pgp or dir in windows environment. but it is throwing following error.

    ----------
    Encountered an error executing the step
    java.util.concurrent.ExecutionException: java.io.IOException: Cannot run program "dir": CreateProcess error=2, The system cannot find the file specified
    at java.util.concurrent.FutureTask$Sync.innerGet(Futu reTask.java:222)
    at java.util.concurrent.FutureTask.get(FutureTask.jav a:83)
    at org.springframework.batch.core.step.tasklet.System CommandTasklet.execute(SystemCommandTasklet.java:1 02)
    at org.springframework.batch.core.step.tasklet.Taskle tStep$2.doInChunkContext(TaskletStep.java:268)
    at org.springframework.batch.core.scope.context.StepC ontextRepeatCallback.doInIteration(StepContextRepe atCallback.java:76)
    at org.springframework.batch.repeat.support.RepeatTem plate.getNextResult(RepeatTemplate.java:367)
    at org.springframework.batch.repeat.support.RepeatTem plate.executeInternal(RepeatTemplate.java:215)
    at org.springframework.batch.repeat.support.RepeatTem plate.iterate(RepeatTemplate.java:143)
    at org.springframework.batch.core.step.tasklet.Taskle tStep.doExecute(TaskletStep.java:242)
    at org.springframework.batch.core.step.AbstractStep.e xecute(AbstractStep.java:198)
    at org.springframework.batch.core.job.AbstractJob.han dleStep(AbstractJob.java:348)
    at org.springframework.batch.core.job.flow.FlowJob.ac cess$0(FlowJob.java:1)
    at org.springframework.batch.core.job.flow.FlowJob$Jo bFlowExecutor.executeStep(FlowJob.java:135)
    at org.springframework.batch.core.job.flow.support.st ate.StepState.handle(StepState.java:60)
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.resume(SimpleFlow.java:144)
    at org.springframework.batch.core.job.flow.support.Si mpleFlow.start(SimpleFlow.java:124)
    at org.springframework.batch.core.job.flow.FlowJob.do Execute(FlowJob.java:103)
    at org.springframework.batch.core.job.AbstractJob.exe cute(AbstractJob.java:250)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher$1.run(SimpleJobLauncher.java:110)
    at org.springframework.core.task.SyncTaskExecutor.exe cute(SyncTaskExecutor.java:49)
    at org.springframework.batch.core.launch.support.Simp leJobLauncher.run(SimpleJobLauncher.java:105)
    at com.emc.eis.concur.ftp.ResourceManagementTest.test LaunchJob(ResourceManagementTest.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.test.context.junit4.SpringTest Method.invoke(SpringTestMethod.java:160)
    at org.springframework.test.context.junit4.SpringMeth odRoadie.runTestMethod(SpringMethodRoadie.java:233 )
    at org.springframework.test.context.junit4.SpringMeth odRoadie$RunBeforesThenTestThenAfters.run(SpringMe thodRoadie.java:333)
    at org.springframework.test.context.junit4.SpringMeth odRoadie.runWithRepetitions(SpringMethodRoadie.jav a:217)
    at org.springframework.test.context.junit4.SpringMeth odRoadie.runTest(SpringMethodRoadie.java:197)
    at org.springframework.test.context.junit4.SpringMeth odRoadie.run(SpringMethodRoadie.java:143)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.invokeTestMethod(SpringJUnit4ClassRu nner.java:160)
    at org.junit.internal.runners.JUnit4ClassRunner.runMe thods(JUnit4ClassRunner.java:51)
    at org.junit.internal.runners.JUnit4ClassRunner$1.run (JUnit4ClassRunner.java:44)
    at org.junit.internal.runners.ClassRoadie.runUnprotec ted(ClassRoadie.java:27)
    at org.junit.internal.runners.ClassRoadie.runProtecte d(ClassRoadie.java:37)
    at org.junit.internal.runners.JUnit4ClassRunner.run(J Unit4ClassRunner.java:42)
    at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestR eference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecutio n.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:197)
    Caused by: java.io.IOException: Cannot run program "dir": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(ProcessBuilder.java :459)
    at java.lang.Runtime.exec(Runtime.java:593)
    at java.lang.Runtime.exec(Runtime.java:431)
    at org.springframework.batch.core.step.tasklet.System CommandTasklet$1.call(SystemCommandTasklet.java:89 )
    at org.springframework.batch.core.step.tasklet.System CommandTasklet$1.call(SystemCommandTasklet.java:1)
    at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.jav a:138)
    at java.lang.Thread.run(Thread.java:619)
    Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessImpl.create(Native Method)
    at java.lang.ProcessImpl.<init>(ProcessImpl.java:81)
    at java.lang.ProcessImpl.start(ProcessImpl.java:30)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java :452)
    ... 7 more
    ----------

    do i need set any path to this issue. Please tell me what needs to be done in window/linux environment.

    thanks in advance.

  5. #5
    Join Date
    Oct 2009
    Location
    San Francisco CA
    Posts
    42

    Default

    Yes, you need to specify the path of the file, it follows the Spring EL for specifying various paths.

  6. #6
    Join Date
    Nov 2009
    Location
    India
    Posts
    15

    Default

    I tried to give fill path for the command property like below.

    <property name="command" value="<<full path>>" /> for the bean SystemCommandTasklet.

    is this correct way. Can you direct me how to do in best way with respective tool path changes.

    Thanks in advance.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •