<p>I have a question about using <code>os.execvp</code> in Python. I have the following bit of code that's used to create a list of arguments:</p>

<pre>
args = [ "java"
       , classpath
       , "-Djava.library.path=" + lib_path()
       , ea
       , "-Xmx1000m"
       , "-server"
       , "code_swarm"
       , params
       ]
</pre>

<p>When I output a string using <code>" ".join(args)</code> and paste that into my shell prompt, the JVM launches fine, and everything works. Everything works if I use <code>os.system(" ".join(args))</code> in my Python script, too.</p>

<p><em>But</em> the following bit of code does not work:</p>

<pre>os.execvp("java", args)</pre>

<p>I get the following error:</p>

<pre>
Unrecognized option: -classpath [and then the classpath I created, which looks okay]
Could not create the Java virtual machine.
</pre>

<p>So what gives? Why does copying/pasting into the shell or using <code>os.system()</code> work, but not <code>os.execvp()</code>?</p>

If your "classpath" variable contains for instance "-classpath foo.jar", it will not work, since it is thinking the option name is "-classpath foo.jar". Split it in two arguments: [..., "-classpath", classpath, ...].
The other ways (copy and paste and system()) work because the shell splits the command line at the spaces (unless they are escaped or quoted). The command line is in fact passed down to the called program as an array (unlike on Windows), and the JVM is expecting to find an element with only "-classpath" followed by another element with the classpath.
You can see the difference for yourself by calling the following small Python script instead of the JVM:
```
```
#!/usr/bin/python
import sys
print sys.argv
```
```