0

In the Python Scrapy framework there is a scrapy.bat file:

@echo off

setlocal

"%~dp0..\python" "%~dp0scrapy" %*
endlocal

Could someone explain what this does? Especially this line "%~dp0..\python" "%~dp0scrapy" %*.

Chris
  • 39,262
  • 15
  • 126
  • 145
DrStrangeLove
  • 9,927
  • 15
  • 55
  • 68

2 Answers2

2

You want to know primarily what %~dp0 means; for that, try taking a look at What does %~dp0 mean, and how does it work? (Remember to search for such things. Search is good.)

Once you understand what %~dp0 means, the rest is easy, but you can get it spelled out by turning a command into an echo statement—echo "%~dp0..\python" "%~dp0scrapy" %*. This is a handy technique in batch file comprehension; poor man's variable inspection.

As for setlocal and endlocal, try (a) help and (b) the power of search.

Community
  • 1
  • 1
Chris Morgan
  • 73,264
  • 19
  • 188
  • 199
1

This is batch syntax. %0 is the first argument which is the path name of the current batch file. ~dp is for path manipulation and means drive and path. In effect, it launches python from a folder up(%~dp0..) and load scrapy module. The %* means pass other arguments passed to the batch to the script.

Eric Fortin
  • 7,323
  • 2
  • 23
  • 31
  • i tried simple example - echo %~dp0 it works! But when i use 1 - echo %~dp1 (or any other digit) it doesnt work! why?? – DrStrangeLove Jan 19 '12 at 15:07
  • How do you call your batch ? If you don't pass argument, you can echo them. Moreover if the first argument is not a pathname, you can't use path expansion with it. – Eric Fortin Jan 19 '12 at 15:57
  • i just double click bat file which contains: echo %~dp0 (and pause) bat file is in Desktop folder. – DrStrangeLove Jan 19 '12 at 18:18
  • That's why you can't print %~dp1, %0 is implicit when you execute the batch file but if you double click on it, you're not passing arguments yourself so there's nothing to print other than %0. – Eric Fortin Jan 19 '12 at 18:26
  • Thanks!! is there a complete guide or reference to batch programming?? Do you know a link?? – DrStrangeLove Jan 19 '12 at 18:30
  • Sure google batch programming and you should get tons of reference. – Eric Fortin Jan 19 '12 at 18:39