Run python script in a console?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Run python script in a console?

Bruce Who

Lately I'm writing a python ftplugin myself and get a problem: I want to add a command to run current python script in a console, when the script terminates the console waits for users to press a key to close itself.

I have tried system():

    call system('python ' . expand('%:p'))

but the console closed immediately. The only workaround is :

    exe '!start cmd /K python ' . expand('%:p')

and this only works on Windows, and it doesn't work like what I need exactly.

Q1: Is there any better solution? If not, then

Q2: Could anybody give me a workaround for Linux?

Besides this, I have another solution which I have not tried yet, write a python.bat file for Windows:

    python %1 %2 %3 %4 %5 %6 %7 %8 %9

and write another shell script for Linux. This may work, but it needs two extra files!

Q3: Is it possible to use system() to call two DOS command(python ... pause) at the same time in the same console? Then I donnot need python .bat anymore.
    Any help would be appreciated!

Best regards,

               Bruce Who