I think you need to prepend cmd.exe to the dir command so something like cmd.exe /C dir
[image: ____________________________________________________________] Mads Nielsen Consultant [email protected] +45 50 98 18 09 <+45%2050%2098%2018%2009> Skype: inkspot Praqma www.praqma.com DK: CPH, Aarhus, Allerod NO: OSL SE: STHLM +45 36 PRAQMA <+4536772762> <http://www.josra.org/blog/An-automated-git-branching-strategy.html?src=mailbanner> On Tue, Jul 19, 2016 at 8:52 AM, <[email protected]> wrote: > Hi, > > I would like to run a Windows command inside my Jenkins Plugin. > > How can I achieve that? > > The following code is not working: > > @Override > public void perform(Run<?,?> build, FilePath workspace, Launcher launcher, > TaskListener listener) { > > try { > > Launcher.ProcStarter > procStarter=launcher.launch().pwd(workspace).cmdAsSingleString("dir " + > workspace + " && attrib -R /S"); > > procStarter= procStarter.stdout(listener); > procStarter.join(); > > } catch (IOException e) { > e.printStackTrace(); > listener.getLogger().println("IOException !"); > } catch (InterruptedException e) { > e.printStackTrace(); > listener.getLogger().println("InterruptedException!"); > } > > } > > > I get the following error when I run a Job that uses this plugin: > > > *java.io.IOException: Cannot run program "dir" (in directory > "C:\LocalJenkins\plugins\michaelPlugin\work\jobs\buildTest\workspace"): > CreateProcess error=2, The system cannot find the file specified* > at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048) > at hudson.Proc$LocalProc.<init>(Proc.java:244) > at hudson.Proc$LocalProc.<init>(Proc.java:216) > at hudson.Launcher$LocalLauncher.launch(Launcher.java:816) > at hudson.Launcher$ProcStarter.start(Launcher.java:382) > at hudson.Launcher$ProcStarter.join(Launcher.java:389) > at > michaelPlugin.michaelPlugin.HelloWorldBuilder.perform(HelloWorldBuild > er.java:110) > at > hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibili > tyLayer.java:75) > at > hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20) > at > hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBui > ld.java:785) > at hudson.model.Build$BuildExecution.build(Build.java:205) > at hudson.model.Build$BuildExecution.doRun(Build.java:162) > at > hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.j > ava:537) > at hudson.model.Run.execute(Run.java:1741) > at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43) > at > hudson.model.ResourceController.execute(ResourceController.java:98) > at hudson.model.Executor.run(Executor.java:408) > Caused by: java.io.IOException: CreateProcess error=2, The system cannot > find th > e file specified > at java.lang.ProcessImpl.create(Native Method) > at java.lang.ProcessImpl.<init>(ProcessImpl.java:386) > at java.lang.ProcessImpl.start(ProcessImpl.java:137) > at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) > ... 16 more > Jul 19, 2016 8:51:12 AM hudson.model.Run execute > INFO: buildTest #52 main build action completed: SUCCESS > > What should be the correct code to run some Windows commands? > > Many thanks > > -- > You received this message because you are subscribed to the Google Groups > "Jenkins Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/jenkinsci-dev/3d3bcaef-9079-4d56-96a7-f09719865a7d%40googlegroups.com > <https://groups.google.com/d/msgid/jenkinsci-dev/3d3bcaef-9079-4d56-96a7-f09719865a7d%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Jenkins Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAFariuurb104qcBjU-qBaVJEmWSvpkete%3D%2BywvhkjZENhQgYnw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
