QnaList > Groups > Scala-User > Aug 2013
faq

Newbie Question On Running System Commands On Windows 7

I’m new to scala and I’m trying to run a system command in a scala script.
 
In Linux, can do:
   import sys.process._
   val result = ("ls").!
 
and it works as expected.
 
In windows:
   import sys.process._
   val result = ("dir").!
 
Gives an error:
java.io.IOException: Cannot run program "dir": CreateProcess error=2, The system
cannot find the file specified
        at java.lang.ProcessBuilder.start(Unknown Source)
        at …
 
I searched the net to find a solution, and found
                http://rosettacode.org/wiki/Execute_a_System_Command
 
Which suggests (obviously for Linux, but the introduction states dir on windows should work):
   import scala.sys.process.Process
   Process("ls", Seq("-oa"))!
 
So I tried Process(“dir”)! with the same results.
 
I’m not a java programmer, but I’m guessing that has something to do with the JVM not behaving correctly and not the Scala Compiler.
 
Any thoughts?
Thanks,
Mike
 
 

asked Aug 1 2013 at 21:44

Michael Shields's gravatar image



3 Replies for : Newbie Question On Running System Commands On Windows 7
OK, OK!  We get that you're new to Scala.  I'm not entirely new to Scala anymore, but I still feel like I'm new to Scala.  The feeling doesn't go away.
Is this one of those Windows things where you have to execute "cmd.exe dir" because there is no standalone "dir.exe"?  Sorry I'm not booted into Windows to check.
With any shell, some commands are built-ins.
My other suggestion is that stackoverflow.com has a lot of eager answerers.  You can post a question like yours which overlaps a couple of domains of expertise and someone somewhere will come up with something useful to say, usually within minutes of your post.
It's kind of annoying, actually, as if some people have their smart phone receive an alert from the SO feed on twitter to buzz their pager (if people still use pagers) so they can excuse themselves from a boring meeting to answer someone's question first and garner those coveted points of repute.  Everyone at the meeting assumes a client issue was escalated and a contract is at stake.
- show quoted text -
- show quoted text -
-- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
 
 

answered Aug 1 2013 at 22:11

som-snytt's gravatar image


Well I'm not in a meeting but anyway... 
scala> import sys.process._
scala> "cmd /K dir".!
/Bjorn
Den fredagen den 2:e augusti 2013 kl. 07:04:04 UTC+2 skrev som-snytt:
- show quoted text -

answered Aug 3 2013 at 06:31

Bjorn Regnell's gravatar image


If you prefer ls :-)
scala> import sys.process._
scala> "powershell -Command ls".!
/Bjorn
Den lördagen den 3:e augusti 2013 kl. 15:24:21 UTC+2 skrev Bjorn Regnell:
- show quoted text -

answered Aug 3 2013 at 06:39

Bjorn Regnell's gravatar image


Related discussions

Tagged

Group Scala-user

asked Aug 1 2013 at 21:44

active Aug 3 2013 at 06:39

posts:4

users:3

©2013 QnaList.com