pass input when running bat

Asked

Viewed 456 times

1

Good afternoon, I have one. bat to run a python file, it needs to receive an entry, but I’m not able to run this input while running . bat, does anyone know how to?

follows information from the bat:

cd C:\Users\Jonathan Pereira\Desktop\ProjetoIruan\Robos\Aranhas\spiders
scrapy crawl imprensa_Nacional -o imprensa_Nacional.csv -s CSV_DELIMITER=";"

follows excerpt from the code that will receive the input:

name = 'imprensa_Nacional'
data = input("Insira uma data: ")
start_urls = ['http://www.imprensanacional.gov.br/leiturajornal?data='+data+'&secao=dou3']
  • Try quotation marks on the path "C: Users Jonathan Pereira Desktop Projetoiruan Robos Spiders Spiders"

  • It didn’t work to do with ""

  • You are trying to run as an administrator?

  • Error when running bat?

1 answer

1


Consider 3 things:

1) Python is not my thing

2) If I understand the question

3) If that’s correct: os.environ['_data'] = 'date'

4) At this link if the most correct is:

       import os  
       name = os.environ.get(_name)
       data = os.environ.get(_data)
 start_urls = os.environ.get(_start_urls)

I’ve done a couple of exchanges of variables between the Bats and Fortran. I think you have to add some lines in the/python script to read the items processed in bat input, what is commented in the code here published.

@echo off & mode 60,9 & color 0a && setlocal enableextensions enabledelayedexpansion

break off && set "_cnt=0"& call :_banner_screen

for /l %%l in (1 2 60) do (

    ping -n 1 127.0.0.0 2>nul >nul && cls & echo/!_double_line!

     if %%l neq 60 ( 

         echo/!_underl:~-%%l!&& echo/!_banner:~-%%l!&& echo/!_underl:~-%%l!
         echo/ & echo/ &echo/!_double_line!

        ) else ( 

         echo/!_underl:~-%%l!&& echo/!_banner!&& echo/!_underl:~-%%l!

        )

)

set /p "_input_data= Insira uma data no formato 'DD/MM/AAAA:"

for /f %%c in ('cmd /u /c set /p "=%_input_data:"= %"^<nul^|find /v /c ""') do call set /a _cnt=%%c + 0

if "!_input_data:~0,2!" leq "0" set _error=on
if "!_input_data:~0,2!" gtr "31" set _error=on

if "!_input_data:~3,2!" leq "0" set _error=on
if "!_input_data:~3,2!" gtr "12" set _error=on

if "!_input_data:~6,4!" leq "2002" set _error=on
if "!_input_data:~6,4!" gtr "!date:~6,4!" set _error=on

if not "!_cnt!" equ "10" (

        echo/& echo/ # E R R O : Data informada esta errada: !_input_data!

        goto :_eof

        ) else if /i "!_error!"=="on" (

        echo/& echo/ # E R R O : Data informada esta errada: !_input_data!

        ) 

         echo/!_input_data!| findstr /l /c:"\/" && set _input_data=!_input_data:/=-!
         echo/!_input_data!| findstr /l /c:"\\\" && set _input_data=!_input_data:/=-!

        )

)

set _data=!_input_data!
set _name=imprensa_Nacional
set _start_urls=[http://www.imprensanacional.gov.br/leiturajornal^?data=!_data!^&secao^=dou3]

cls && mode 82,9  &&  echo/!data! & echo/!name! & echo/!start_urls! 

echo/  No script python, adicione esses itens: 
echo/ ----------------------------------------
echo/ os.environ['_data'] = 'data'
echo/ os.environ['_name'] = 'name'
echo/ os.environ['_start_urls'] = 'start_urls'

timeout /t 10 >nul

if exist "C:\Users\Jonathan Pereira\Desktop\ProjetoIruan\Robos\Aranhas\spiders\scrapy.*" (

     pusd "C:\Users\Jonathan Pereira\Desktop\ProjetoIruan\Robos\Aranhas\spiders"

     .\scrapy crawl imprensa_Nacional -o imprensa_Nacional.csv -s CSV_DELIMITER=";"

     popd 

    )    

goto :_eof

:_banner_screen

(

set _double_line=^


set _double_line=!_double_line!^!_double_line!
set "_underl= _________________________________________________________"
set _banner=^
 __________* I M P R E N S A * N A C I O N A L *__________

break on && exit /b

)

:_eof
  • Thanks for the explanation, in the end it was not necessary to implement anything inside the code, because the function I created inside the file already performed this processing :) Thanks for the teaching.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.