简体   繁体   English

如何处理批处理脚本中的退出代码?

[英]How to handle exit code in batch script?

I have a batch script which eventually runs two python file (one after another), but I am unable to handle the exit code from one workflow to another.我有一个批处理脚本,它最终运行两个 python 文件(一个接一个),但我无法处理从一个工作流到另一个工作流的退出代码。 Due to which my batch script is failing由于我的批处理脚本失败

batch file snippet:批处理文件片段:

@echo off
echo "Starting the automation Script"
cd "C:\Desktop\AutoImpement\"
echo "running the loging"
    start python login.py
    start python OrderTicket.py             
pause

login script:登录脚本:

import time
from selenium import webdriver
browser = webdriver.Chrome(executable_path="C:\Desktop\AutoImpement\ChromeDriver")
browser.get('https://localhost:8080/login/#') 
browser.find_element_by_id(“Login”).send_keys(“<userName>”)
browser.find_element_by_id (“Password”).send_keys(“password”)
browser.find_element_by_id(“submit”).click()
time.sleep(5)
browser.find_element_by_id(“ItemName”).send_keys(“test”)
browser.find_element_by_id (“Quantity”).send_keys(“5”)
browser.find_element_by_id(“Address”).send_keys(“Test”)
browser.find_element_by_id(“submitOrder”).click()
time.sleep(3)
browser.quit()

Verify the Order Script验证订单脚本

import time
from selenium import webdriver

browser = webdriver.Chrome(executable_path="C:\Desktop\AutoImpement\ChromeDriver")
browser.get('https://localhost:8080/OrderDetails') 
browser.find_element_by_id(“SreachOrder”).send_keys(“test”)
browser.find_element_by_id(“findOrder”).click()
time.sleep(3)
browser.quit()

When I run the batch file, only the login script is running successfully but the control is not shifting to the next script which verifies the order from the first file.当我运行批处理文件时,只有登录脚本成功运行,但控制权不会转移到下一个脚本来验证第一个文件的顺序。 I tried with sending the exit code from the python by changing the following but didn't work.我尝试通过更改以下内容从 python 发送退出代码,但没有用。

import time
from selenium import webdriver
try:
    browser = webdriver.Chrome(executable_path="C:\Desktop\AutoImpement\ChromeDriver")
    browser.get('https://localhost:8080/login/#') 
    browser.find_element_by_id(“Login”).send_keys(“<userName>”)
    browser.find_element_by_id (“Password”).send_keys(“password”)
    browser.find_element_by_id(“submit”).click()
    time.sleep(5)
    browser.find_element_by_id(“ItemName”).send_keys(“test”)
    browser.find_element_by_id (“Quantity”).send_keys(“5”)
    browser.find_element_by_id(“Address”).send_keys(“Test”)
    browser.find_element_by_id(“submitOrder”).click()
    time.sleep(3)
    exit(0)
except:
    print("Error Occured")
    exit(1)
finally:
browser.quit()

In the above case in your batch file.在上述情况下,在您的批处理文件中。 Both the Scripts will run simultaneously.两个脚本将同时运行。 Remove Start python login.py python OrderTicket.py删除 Start python login.py python OrderTicket.py

The Second will run only after first is complete.第二个只会在第一个完成后运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM