running system command on windows 8.1

60 views
Skip to first unread message

Mike Shields

unread,
Jan 16, 2015, 6:25:43 PM1/16/15
to scala...@googlegroups.com

Hi,

 

I’m trying to use Process to run system commands and it doesn’t seem to work. I seem to recall that this worked previously, but I could find my old code. For example to make a directory, in the REPL I do the following:

 

scala> import sys.process._

import sys.process._

 

scala> Process("md tt")!

 

But I get the following warning and nothing happens:

 

warning: there was one feature warning; re-run with -feature for details

java.io.IOException: Cannot run program "md": CreateProcess error=2, The system

cannot find the file specified

  at java.lang.ProcessBuilder.start(Unknown Source)

  at scala.sys.process.ProcessBuilderImpl$Simple.run(ProcessBuilderImpl.scala:69

)

  at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.run(ProcessBuilderImpl

.scala:98)

  at scala.sys.process.ProcessBuilderImpl$AbstractBuilder.$bang(ProcessBuilderIm

pl.scala:112)

  ... 33 elided

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>(Unknown Source)

  at java.lang.ProcessImpl.start(Unknown Source)

  ... 37 more

 

If I exit the REPL and in the same command prompt do

D:\scala\temp>md tt

 

It works as expected. I recently upgraded to Windows 8.1 and I’m thinking maybe there is some permission for java that is not set correctly.

 

Any ideas?

 

Thanks,

Mike

 

Daniel Armak

unread,
Jan 17, 2015, 12:04:22 PM1/17/15
to Mike Shields, scala...@googlegroups.com

Are you sure md is a genuine executable and not a Windows shell builtin? Is there an “md.exe” somewhere and is it on your path?


Daniel Armak

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Siddhartha Gadgil

unread,
Jan 17, 2015, 12:24:09 PM1/17/15
to scala...@googlegroups.com, mshi...@vigilantsys.com
If I recollect correctly, one has to run "cmd" (the dos command shell) and pass the appropriate command to it (since md is not an executable, but interpreted by the command shell.

Siddhartha

Daniel Armak

unread,
Jan 17, 2015, 12:42:58 PM1/17/15
to Siddhartha Gadgil, scala-user, Mike Shields
Alternatively, you could write and run a .bat file. 

Daniel Armak

--

Mike Shields

unread,
Jan 17, 2015, 5:47:23 PM1/17/15
to Siddhartha Gadgil, scala-user

I figured it out. The correct syntax is ot include a /C after the cmd as:

 

scala> Process("cmd /C md \\tt")!

res9: Int = 0

 

Thanks,

Mike

Reply all
Reply to author
Forward
0 new messages