Using Python To Launch Python

Aquil H. Abdullah aquil.abdullah at gmail.com
Tue Jul 15 10:42:32 EDT 2008


Ahh, Win-BASH cool!!!

On Tue, Jul 15, 2008 at 10:41 AM, Aquil H. Abdullah <
aquil.abdullah at gmail.com> wrote:

> Ack, .bat files! Yes, you are correct Windows does not ship with Python,
> and there are ways to get bash (cygwin) on your Windoze system.  I am
> leaning towards a solution similar to your second suggestion as it will keep
> me from having to distribute .bat files for one platform and .sh files for
> another.  Thank you for all of your suggestions.
>
>
> On Mon, Jul 14, 2008 at 8:39 PM, Derek Martin <code at pizzashack.org> wrote:
>
>> On Mon, Jul 14, 2008 at 05:40:43PM -0400, Aquil H. Abdullah wrote:
>> > You've hit the proverbial nail with the hammer.  The problem is that my
>> > application needs to run under both the Linux and Windows OSs, so while
>> I
>> > would love to use a nice sh, csh, or bash shell script. My hands are
>> tied
>> > because Windows does not provide such wonderful shells.
>>
>> *Provides*, no... neither does it provide Python, for what that's
>> worth.  But you can certainly get it (bash):
>>
>>  http://win-bash.sourceforge.net/
>>
>> I suppose it's not worth installing just for this purpose though...
>> But you can provide with your application a DoS batch file that does
>> exactly the same thing (in addition to a shell script).  The user
>> would quite intuitively use whichever were appropriate, or follow your
>> provided directions otherwise.  Or, the equivalent in (hopefully
>> OS-agnostic) Python:
>>
>> import os, sys
>>
>> # I believe this gets the name of the root in all major OSes
>> def root_dir(path):
>>        if os.path.dirname(path) == path:
>>                return path
>>        return (root_dir(os.path.dirname(path)))
>>
>> appname = <name of your python script>
>> root = root_dir(os.getcwd())
>> install_path = os.path.join(root, "usr")
>> bin_path = os.path.join(install_path, "bin")
>> os.environ["PATH"] = bin_path + os.pathsep + os.environ["PATH"]
>> python_path = os.path.join(bin_path, "python")
>> args = sys.argv[1:]
>> args.insert(0, os.path.join(bin_path, appname))
>> args.insert(0, python_path)
>> args.insert(0, python_path)
>> os.execv(python_path, args)
>>
>>
>>
>>
>
>
> --
> Aquil H. Abdullah
> aquil.abdullah at gmail.com
>



-- 
Aquil H. Abdullah
aquil.abdullah at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080715/a794b3a0/attachment-0001.html>


More information about the Python-list mailing list