Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #42830

Run python script with ./

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <luban.works@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'scripts': 0.03; 'linux,': 0.07; '%s"': 0.09; 'exec': 0.09; 'exit': 0.09; 'skip:/ 10': 0.09; 'subject:script': 0.09; 'wrapper': 0.09; 'python': 0.11; 'systems.': 0.12; '"python"': 0.16; '2.7.3': 0.16; 'script,': 0.16; '\xa0\xa0\xa0\xa0\xa0\xa0': 0.16; 'subject:python': 0.16; 'skip:# 20': 0.16; 'all,': 0.19; 'work,': 0.20; 'command': 0.22; 'print': 0.22; 'script.': 0.24; 'question': 0.24; 'script': 0.25; '&gt;': 0.26; 'skip:" 20': 0.27; 'installed': 0.27; 'skip:p 30': 0.29; 'message-id:@mail.gmail.com': 0.30; 'work:': 0.31; 'file': 0.32; 'run': 0.32; 'another': 0.32; 'beginning': 0.33; 'skip:# 10': 0.33; 'skip:& 30': 0.33; 'subject:with': 0.35; 'received:209.85': 0.35; 'received:209.85.220': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'found.': 0.36; 'skip:> 10': 0.36; 'so,': 0.37; 'two': 0.37; 'received:209': 0.37; 'skip:& 10': 0.38; 'work?': 0.38; 'skip:[ 10': 0.38; 'to:addr :python-list': 0.38; 'skip:. 10': 0.39; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; 'unable': 0.39; 'skip:p 20': 0.39; 'how': 0.40; 'skip:c 50': 0.60; 'skip:* 10': 0.61; 'such': 0.63; 'different': 0.65; 'header:Reply-To:1': 0.67; 'home': 0.69; 'reply-to:no real name:2**0': 0.71; 'export': 0.74; 'reply- to:addr:gmail.com': 0.80; 'skip:$ 10': 0.81; 'skip:/ 30': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:reply-to:date:message-id:subject:from:to :content-type; bh=bZRbS77eweCIlaIIZbZ/dHcRF1h3B89PtXw2PQbpzOE=; b=qbDezzb0qZiAuxHicotm2BA5ONQWipwZ5on49fRuFhSZqJnoSPAJkp6dczXdAALKd8 jzkkpC6QFUpptjt6WCWoVsQcb4cd8QbSGU4E3amz1c/3hNsM0kg00S0pkgRhqCGmbWcs N2kqZ//r6ls9X4ddaHbJY8y0SUeitO8XaZLqPajDiClAwXdfyVrPTY3ppKpmGplYNpxp ffNNtRYevnmZrtpVLUea8sBOcW5X+y8Dy6h4XlRGwBGTaox+WbjRAiZ/JkP/4eOmxwMN 7jbCKMNWf/zsyYSAyzS19EJTLsmYdZphIsLkqNFZXTj+hyMnONItS/bzg5l43iuo2mtw eM4Q==
MIME-Version 1.0
X-Received by 10.58.213.37 with SMTP id np5mr8259217vec.54.1365174283965; Fri, 05 Apr 2013 08:04:43 -0700 (PDT)
Date Fri, 5 Apr 2013 23:04:43 +0800
Subject Run python script with ./
From LubanWorks <luban.works@gmail.com>
To python-list@python.org
Content-Type multipart/alternative; boundary=047d7bea3f9840a07204d99e6849
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To LubanWorks@gmail.com
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.145.1365174292.3114.python-list@python.org> (permalink)
Lines 163
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1365174292 news.xs4all.nl 6975 [2001:888:2000:d::a6]:54416
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:42830

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

Hi all,
    I installed two python 2.7.3 into my home directory

       one is for Linux:           /home/luban/*Linux*/Python/2.7.3
       another is for Solaris:   /home/luban/*SunOS*/Python/2.7.3

then I create a wrapper named "python" in /home/luban/bin to call the
different python when I am working on different systems.

[luban@lunbanworks 1] ~ > cat /home/luban/bin/python

#!/bin/sh

CMD=`basename $0`

OS=`uname -s`


CMD_PATH="/home/luban/$OS/Python/2.7.3/bin"


if [ -x "${CMD_PATH}/${CMD}" ];then

    export PATH="${CMD_PATH}:${PATH}"

    exec ${CMD_PATH}/${CMD} ${1+"$@"}

else

    echo "${CMD} is not available for ${OS}" 1>&2

exit 1

fi

[luban@lunbanworks 2] ls -l /home/luban/bin/python
-rwxrwxr-x  1 luban lunban  221 Apr  5 19:11 python*


I use below script to  test the wrapper /home/luban/bin/python

[luban@lunbanworks 3]* ~ > *cat myscript.py
#!/home/luban/bin/python

myname="lunban"

print "myname is %s" % myname

[luban@lunbanworks 4]* *chmod +x myscript.py

I want to use ./ run myscript.py

[luban@lunbanworks 5] ~ >./myscript.py
myname=luban: Command not found.
lpr: Unable to access "myname" - No such file or directory


use /home/luban/bin/python myscript.py can work:*

*[luban@lunbanworks 5] ~ > */home/luban/bin/python myscript.py*
myname is luban


After I *change the shebang line to
#!/home/luban/Linux/Python/2.7.3/bin/python, use ./ can execute the script.
*
[luban@lunbanworks 6] *~ >*cat myscript.py
#!/home/luban/Linux/Python/2.7.3/bin/python
myname="lunban"

print "myname is %s" % myname

[luban@lunbanworks 7] *~ >*./myscript.py
myname is luban


My question is:

Why  when I use #!/home/luban/Linux/Python/2.7.3/bin/python at the
beginning of myscript.py, *./*myscript.py can work,

but if I use the wrapper #!/home/luban/bin/python in my python script, use *
./*  to run the script, it cannot not work?


I had many scripts used #!/home/luban/bin/python when I only installed
python  under #!/home/luban/ for Linux, they can run with ./, I don't want
to change them,

so, how to let ./ run the python script If I want to *KEEP* wrapper
#!/home/luban/bin/python as the shebang line?


Best Regards,
Luban

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Run python script with ./ LubanWorks <luban.works@gmail.com> - 2013-04-05 23:04 +0800

csiph-web