First, there's no such method as System.exec(). The exec() methods are in the Runtime class.
You never need to import java.lang classes. If you get a compile-time error, it's never worth trying that. Note however that, if you use sub-packages of java.lang, such as java.lang.reflect, you would need to import those (but not in your example).
If your example, of running "cd", is what you really intend to do, then it won't work. If it ran at all, which it probably won't, it would only change the working directory of the spawned process, not the Java one. In fact, you can't change the working directory of a Java process (someone correct me if I'm wrong). There is, however, a version of exec() that allows you to specify a working directory for spawned processes.
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
posted 14 years ago
When you say spawned processes what are you refering to? I only want to execute a command like this in C:
system("cd"); //here you can invoke the operating system command cd.
I'm new in Java, but I think there is a command to execute an operating system command.
I don't know if you know C (I so) and with this language I can invoke an operating system command using system("OS command"). Is it possible to do it in Java? I think so.
Running the "cd" command won't work in C either. All the system() command does is start a command shell, to change the current working directory, which will be immediately be lost when the command shell exits.
However, you can do something similar with the Runtime class, you just have one level of indirection. You need to exec the shell which can exec the command.