473,574 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

windows bat file question

I'm trying to get pylint running on windows and the bat file for it
seems a little screwy. I'm hoping someone may have figured this out
already.

rem = """-*-Python-*- script
@echo off
rem -------------------- DOS section --------------------
rem You could set PYTHONPATH or TK environment variables here
python %*
goto exit

"""
# -------------------- Python section --------------------
import sys
from logilab.pylint import lint
lint.Run(sys.ar gv[1:])
DosExitLabel = """
:exit
rem """

All I get is the python prompt, the lines starting at import sys don't
run. If I throw the lines in a python script, I run into path issues.

The overall effect I'm trying to achieve is....

c:\Projects\myp roject\pylint mymodule.py

Any ideas?

--
Thomas G. Willis
http://paperbackmusic.net
Jul 18 '05 #1
11 3271
Tom Willis wrote:
I'm trying to get pylint running on windows and the bat file for it
seems a little screwy. I'm hoping someone may have figured this out
already.
...
All I get is the python prompt, the lines starting at import sys don't
run. If I throw the lines in a python script, I run into path issues.


What exact command are you typing to try to run it? Where is
the script relative to the current directory? (Best is to
cut and paste a copy of the actual command line and result
that you have in your console.)

On the topic of the "path issues" in the other case, what do you
mean by path issues? DOS path issues? sys.path issues? Something
else? What issues exactly...

-Peter
Jul 18 '05 #2
On Tue, 01 Mar 2005 10:12:29 -0500, Peter Hansen <pe***@engcorp. com> wrote:
Tom Willis wrote:
I'm trying to get pylint running on windows and the bat file for it
seems a little screwy. I'm hoping someone may have figured this out
already.
...
All I get is the python prompt, the lines starting at import sys don't
run. If I throw the lines in a python script, I run into path issues.


What exact command are you typing to try to run it? Where is
the script relative to the current directory? (Best is to
cut and paste a copy of the actual command line and result
that you have in your console.)

On the topic of the "path issues" in the other case, what do you
mean by path issues? DOS path issues? sys.path issues? Something
else? What issues exactly...

-Peter
--
http://mail.python.org/mailman/listinfo/python-list


I figured it out. I just took the embedded python code that was in the
batch file distributed with it and put it in it's own module.

Really my question was how would this ever work? It seems to me to be
a little screwy, but it would be handy to know if this was some sort
of convention that I could take advantage of if I ever write something
substantial that would need to run on windoze.
REM---bat file---
rem = """-*-Python-*- script
@echo off
rem -------------------- DOS section --------------------
rem You could set PYTHONPATH or TK environment variables here
python %*
goto exit

"""
# -------------------- Python section --------------------
print "hello from python"

DosExitLabel = """
:exit
rem """
REM---end of bat file---

I'm wondering if this took advantage of some flaw in batch file
processing that can no longer be used because of some security hole
that got plugged or something.


--
Thomas G. Willis
http://paperbackmusic.net
Jul 18 '05 #3
Tom Willis wrote:
On Tue, 01 Mar 2005 10:12:29 -0500, Peter Hansen <pe***@engcorp. com> wrote:
Tom Willis wrote:
I'm trying to get pylint running on windows and the bat file for it
seems a little screwy. I'm hoping someone may have figured this out
already.
...
All I get is the python prompt, the lines starting at import sys don't
run. If I throw the lines in a python script, I run into path issues.


What exact command are you typing to try to run it? Where is
the script relative to the current directory? (Best is to
cut and paste a copy of the actual command line and result
that you have in your console.)

On the topic of the "path issues" in the other case, what do you
mean by path issues? DOS path issues? sys.path issues? Something
else? What issues exactly...

-Peter
--
http://mail.python.org/mailman/listinfo/python-list

I figured it out. I just took the embedded python code that was in the
batch file distributed with it and put it in it's own module.

Really my question was how would this ever work? It seems to me to be
a little screwy, but it would be handy to know if this was some sort
of convention that I could take advantage of if I ever write something
substantial that would need to run on windoze.
REM---bat file---
rem = """-*-Python-*- script
@echo off
rem -------------------- DOS section --------------------
rem You could set PYTHONPATH or TK environment variables here
python %*
goto exit

"""
# -------------------- Python section --------------------
print "hello from python"

DosExitLabel = """
:exit
rem """
REM---end of bat file---

I'm wondering if this took advantage of some flaw in batch file
processing that can no longer be used because of some security hole
that got plugged or something.

It was clearly originally intended to be run as "name" and then pipe the
batch file into the Python interpreter, but as to how the hell it was
actually supposed to work, your guess is as good as mine.

regards
Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005 http://www.pycon.org/
Steve Holden http://www.holdenweb.com/
Jul 18 '05 #4
Tom Willis wrote:
I figured it out. I just took the embedded python code that was in the
batch file distributed with it and put it in it's own module.

Really my question was how would this ever work? It seems to me to be
a little screwy, but it would be handy to know if this was some sort
of convention that I could take advantage of if I ever write something
substantial that would need to run on windoze.


It looks like it might have been an untested version of something
that should have been using "python %0 %*" at that line instead
of just "python %*".

Under Windows XP (and probably NT, but not 98) the %* means
"all arguments", but doesn't appear (in testing just now on
my own machine) to include the name of the batch file itself.

On the other hand, %0 does include the name of the batch file,
but unfortunately it's actually just the part that you typed,
as in "blah" instead of "blah.bat" if you executed the file
by typing just "blah" instead of "blah.bat".

All things considered, it does look like it could never have
worked properly, but Windows is freakish enough that there
might well be some sequence of events and set of conditions
under which it might actually work as intended...

Of course, if you're on XP where you could hope that the
%* magic could work at all, you can also just modify the
contents of the environment variable PATHEXT to include .py,
rename the script to .py and strip out all that crappy
BAT stuff, and run it as intended with (almost) no
complications.

-Peter
Jul 18 '05 #5
Tom Willis <to********@gma il.com> wrote:
I'm trying to get pylint running on windows and the bat file for it
seems a little screwy. I'm hoping someone may have figured this out
already.

rem = """-*-Python-*- script
@echo off
rem -------------------- DOS section --------------------
rem You could set PYTHONPATH or TK environment variables here
python %*
This should make it work:
python %0.bat %*
goto exit

"""
# -------------------- Python section --------------------
import sys
from logilab.pylint import lint
lint.Run(sys.a rgv[1:])
DosExitLabel = """
:exit
rem """

--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jul 18 '05 #6
Tim Roberts wrote:
Tom Willis <to********@gma il.com> wrote:
rem = """-*-Python-*- script
@echo off
rem -------------------- DOS section --------------------
rem You could set PYTHONPATH or TK environment variables here
python %*


This should make it work:
python %0.bat %*


Only, among other issues, if you type the full path to the
batch file, or if it's in the current directory. This
approach fails if you put the batch file in a directory
somewhere along your path.

There are only a couple of useful ways to do this sort of
thing under Windows operating systems, and the easiest by
far is to abandon any support for Windows 98 and just use
the PATHEXT support in Windows NT/XP and friends.

-Peter
Jul 18 '05 #7
Peter Hansen wrote:
This should make it work:
python %0.bat %*
Only, among other issues, if you type the full path to the
batch file, or if it's in the current directory. This
approach fails if you put the batch file in a directory
somewhere along your path.


The simplest fix, assuming we aren't talking Win9x is probably:

python "%~f0" %*
There are only a couple of useful ways to do this sort of
thing under Windows operating systems, and the easiest by
far is to abandon any support for Windows 98 and just use
the PATHEXT support in Windows NT/XP and friends.


And if you can't be bothered with PATHEXT then just make sure to always
type the .py in as part of the command line:

C:\>myscript.py

will run a Python script without any messing. If the script is in the
current directory then you can use tab completion to avoid typing the whole
name anyway.

Jul 18 '05 #8
Duncan Booth wrote:
Peter Hansen wrote:
This should make it work:
python %0.bat %*


Only, among other issues, if you type the full path to the
batch file, or if it's in the current directory. This
approach fails if you put the batch file in a directory
somewhere along your path.

The simplest fix, assuming we aren't talking Win9x is probably:

python "%~f0" %*


Wow. The myriad things that get slipped into these little
operating systems while you aren't looking. Windows XP's command
shell begins to border on being marginally acceptable for some
limited types of scripting.

Unfortunately, Google makes it hard to search for such things,
but after a while I was able to dig up this master reference:

http://www.microsoft.com/resources/d...s/percent.mspx

Thanks, Duncan!

-Peter
Jul 18 '05 #9
Peter Hansen wrote:
Unfortunately, Google makes it hard to search for such things,
but after a while I was able to dig up this master reference:

http://www.microsoft.com/resources/d...xp/all/proddoc
s/en-us/percent.mspx


You will find even more information if you try 'set /?' or 'for /?' at a
command prompt. As you say, you can now do quite complicated scripting in
command files but it needs masochism second only to Perl programming.

Jul 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
7078
by: sebastien.hugues | last post by:
Hi I would like to retrieve the application data directory path of the logged user on windows XP. To achieve this goal i use the environment variable APPDATA. The logged user has this name: sébastien. The second character is not an ascii one and when i try to encode the path that contains this name in utf-8,
2
1406
by: mio | last post by:
Hi We have a WEB-based application (developed in Visual Studio 2005) running on handheld devices in Internet Explorer on Windows Mobile 2003. The application needs to print tickets on a Bluetooth printer, which is accomplished by preparing a RTF-file on the server and then downloading this file to the handheld device. We use a third-party...
54
8944
by: Sathyaish | last post by:
I am trying to print to the printer. I am using a VC++ 6.0 compiler on Win 2K, but I get an error saying that stdprn is not defined. Why is that? Is it because of Windows, I am guessing? Do I have to use only the GDI32 functions for printing under Windows? Can I not use the stdprn under Windows to print from memory to the window?
7
5793
by: Luc The Perverse | last post by:
Hello! I am looking for a beginners tutorial on how to program for windows in C. I guess this is windows API? I have never written outside of VC++ for windows, and can't find any examples. I don't think that this is a DevC++ specific question. I have written a simple application which locates duplicate files; it first compares file...
3
14882
by: Amjad | last post by:
Hi, I just wrote a test Windows Service that creates a text file on startup (please see my code below). The file is never created. Protected Overrides Sub OnStart(ByVal args() As String) Dim swLog As StreamWriter = File.CreateText("C:\myLog.txt") swLog.WriteLine("My Windows Service has just started.") swLog.Close() : swLog.Flush() End Sub
0
1262
by: tony | last post by:
Hello! I have one solution file that consist of three project. One project that build the exe file. One project that build a class library dll One project that build a windows control dll In the windows control c-tor is there a call to a method in the class libarary. So in the project referense settings for the windows control I have a
6
595
by: Chris Marsh | last post by:
All I have a database table, changes to the data within which I am interested in acting on. The approach that I'm taking is to have the database update a file every time data is updated. This process is outside my domain - I can rely on the file being updated when data changes. Within my domain is the design of a Windows service to...
60
7925
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type? ----------------------------------------------------------------------- It is not possible with client-side JavaScript. Some browsers accept the Content-Disposition header, but this must be...
1
4582
by: CSharpner | last post by:
Short Question: How do I support Cut/Paste to/from a .NET app and Windows Explorer? Full Text: I'm nearing the completion of a Remote File Management application. It looks and feels a lot like Windows Explorer. The difference is that it communicates with a remote server via web services. The remote web services store and retrieve the...
5
3290
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name? Why do I need to set a property within my code to the service name? Are all these required or am I just doing this for consistency purposes?
0
7797
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7715
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7806
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8093
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6440
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5611
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3739
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3748
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1333
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.