ตรวจสอบค่า exit code

Prawit Tangmanopeanchai
1 min readDec 23, 2019

--

วิธีตรวจค่า exit code หรือ return code หลังจากจบโปรแกรมเพื่อนำไปใช้ในการพัฒนา script หรือนำไปใช้ร่วมกับเครื่องมืออื่น ๆ เช่นการทำ custom check สำหรับ nagios หรือใช้กับ BMC Control-M

สำหรับ Windows ค่า exit code จะดูได้จาก %errorlevel%

ส่วนของ Unix/Linux ค่า exit code จะดูได้จาก $?

PowerShell ค่า exit code จะดูได้จาก $? แต่จะได้ค่าเป็น True หรือ False เท่านั้น

หากต้องการ exit code จาก powershell ให้แสดงเป็นตัวเลขให้ run script ของ powershell ผ่าน cmd แล้วดูค่า exit code จาก %errorlevel%

เช่น run คำสั่ง “powershell dir” ที่ command prompt ของ CMD

ขอบคุณ น้องมีน ที่หาข้อมูลให้ครับ

--

--

Prawit Tangmanopeanchai
Prawit Tangmanopeanchai

Written by Prawit Tangmanopeanchai

Head of Cloud Implementation Unit at gosoft (Thailand)

No responses yet