LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-01-2021, 04:06 PM   #1
sloven0317
LQ Newbie
 
Registered: Jul 2016
Posts: 5

Rep: Reputation: Disabled
Error Checking in a script


Using the following script to test error codes - want to distinguish between a non existing file and a file that won't fit on destination

if I set XX to 15 which is a non existing file name - I get an errorlevel 4 instead of a 1
if I set XX to 20 which is an existing file name - I get an errorlevel 0 which is correct
if I set XX to 25 which is a file too big to write on the disk - I get the message
Insufficient disk space on current disk.
Insert another disk and type to continue...
instead of an errorlevel 4 which is what I would expect

Where am I going wrong - tried switches /c and /q also but no difference
Sorry for my previous code mess-ups

----------------------code--------------
D:
cd
cd Backup_Staging
xcopy Test2021-08-XX.7z E: /y
if errorlevel 4 (
echo The program returned error level 4 - not enough available disk space
goto end
)
if errorlevel 1 (
echo The program returned error level 1 - source doesn't exist
goto end
)
if errorlevel 0 (
echo The program returned error level 0 - successful copy
goto end
)
d:\Bin\sleep 5
:end
echo Done!
 
Old 09-01-2021, 07:20 PM   #2
Keith Hedger
Senior Member
 
Registered: Jun 2010
Location: Wiltshire, UK
Distribution: Linux From Scratch, Slackware64, Partedmagic
Posts: 2,950

Rep: Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784Reputation: 784
Two things:
1)
Use code tags
2)
Looks like you are programming on windows this forum is predominantly linux, You will probably get better help in a windows forum.
 
1 members found this post helpful.
Old 09-01-2021, 07:56 PM   #3
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,715
Blog Entries: 11

Rep: Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747Reputation: 3747
Welcome to the Programming forum!

Quote:
Originally Posted by Keith Hedger View Post
Looks like you are programming on windows...
Indeed! I held off posting in hope that someone else might recognize the code as I did not!

While the forum is not limited to Linux related programming questions and your questions from other platforms are welcome, it is still a fact that the members offering help here are mostly Linux oriented, so you may have to wait for someone with the required knowledge to happen by!

And as helpfully pointed out already, please wrap your code and data snippets inside [CODE]...[/CODE] tags. Doing so will preserve indentation and provide other visual clues which make it easier for others to comprehend. You may write those yourself as shown, or use the # button available with Advanced edit options. (A complete list of BBCode tags is always available via a link near the bottom of every thread view).

Good luck!
 
  


Reply

Tags
scripting


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Script to trigger second script--second script gets arguments of first script keif Linux - General 10 08-12-2021 01:25 AM
[SOLVED] Shell Script is showing error after whenever checking a special variable emcykm Linux - Newbie 5 06-01-2011 09:59 AM
nice little shell script needs some "error checking" help pendal Programming 2 10-18-2009 11:06 AM
Dependency checking this, dependency checking that. Jeebizz General 11 09-29-2009 06:51 PM
Proccess checking within shell script khutze Programming 2 08-12-2002 01:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration