开发者

From within a Rhino JS console run CD produces exception

When attempting runCommand("cd", "..") from inside a js.jar console a开发者_如何学Gon IOException is thrown.

I believe it's because in the command prompt the CD command is actually built into the console and not a separate .exe file. The runCommand("notepad") works fine, and that .exe can be found on the classpath in the usual location.

Is there a work around for this?

I was thinking that changing the directory through java instead of through the command prompt it might solve this problem, but I don't recall how to do that from java, but I plan on trying to figure that out.

To sum up: Is there a way to run "cd" from within a Rhino JS console on windows?

Thanks, L-


Multiple issues to solve here; it depends what you are trying to do.

runCommand actually runs executable programs. cd is not an executable on Windows; it is a command in the command shell. So you would need to execute something more like this:

runCommand("cmd","/c","cd <target-directory>")

However, the underlying Java runtime does not allow you to actually change the working directory anyway. See this StackOverflow discussion. So shelling out cd just changes the directory for the subprocess (the process running cd), which is probably not what you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜