delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/08/06/12:39:48

X-Spam-Check-By: sourceware.org
Date: Sun, 6 Aug 2006 12:39:33 -0400 (EDT)
From: Igor Peshansky <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: Shane <wolfpack AT inbox DOT com>
cc: cygwin AT cygwin DOT com
Subject: Re: Checking XCOPY Exit Value in Cygwin Bash
In-Reply-To: <74382BAFEAA.000000D2wolfpack@inbox.com>
Message-ID: <Pine.GSO.4.63.0608061222390.3283@access1.cims.nyu.edu>
References: <74382BAFEAA DOT 000000D2wolfpack AT inbox DOT com>
MIME-Version: 1.0
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Sun, 6 Aug 2006, Shane wrote:

> Hi all,

Hi.  <http://cygwin.com/acronyms/#PCYMTWLL>.  Reading the one-line below
was extremely painful in the web archives.  See for yourself:
<http://cygwin.com/ml/cygwin/2006-08/msg00169.html>.

>        I am writing a automated build script for my project that will be
> run under cygwin. I will copy my updated source files to the build
> directory and if there are updated files, the executables will be built.
> To copy the source files, I had to use XCOPY since the directory
> structure should be preserved in the destination directory also.

Nope, you didn't have to.  Something like

(cd "$2/.." && find "$2" -name "*.$1" | tar cfT - -) | tar xfC - "$3"

would do the job of "XCOPY /S" using POSIX means.

> To copy only the updated files, I used the /D switch for XCOPY.

If you go POSIX, you can use the --keep-newer-files tar option.

> Now since I want
> to execute the source compile only if files in the build directory have
> been updated, I have to use the exit codes of XCOPY inside the script. I
> tried checking the value of $! after executing XCOPY but it didnt work.

Of course it didn't.  Please read a good bash tutorial, or the "Special
Parameters" section of the bash manpage.

> I couldn't find a solution in the internet too.  Currently I am piping
> the standard output to a file and checking if the number of files copied
> is 0 or not. But I think this is not an elegant solution. This is what I
> am doing now.
>
> [script]
> copied=false
> # Helper Function
> copy_files()
> {
>     echo copying *.$1 files in $2 to $3\\$2
>     xcopy /DSYI $2\\*.$1 $3\\$2 | tee copy.log
>
>     while read amount  ; do
>         if [ ${amount::1} != "0" ]; then
>             copied=true;
>         fi
>     done < copy.log
> }
> cd ../source
>
> copy_files h    . ..\\build
> copy_files c    . ..\\build
> copy_files cpp  . ..\\build
> rm -f copy.log
> ! $copied && echo "Files up-to-date. Skipping build" && exit 0
> cd ../build
> # Start the Build Process
> [/script]
>
> Can you please provide me a way of checking the XCOPY exit code:
> reference
> [http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true]
> within Bash?

It's just like checking any other exit code in bash: reference "man bash".
HTH,
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_	    pechtcha AT cs DOT nyu DOT edu | igor AT watson DOT ibm DOT com
ZZZzz /,`.-'`'    -.  ;-;;,_		Igor Peshansky, Ph.D. (name changed!)
     |,4-  ) )-,_. ,\ (  `'-'		old name: Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Las! je suis sot... -Mais non, tu ne l'es pas, puisque tu t'en rends compte."
"But no -- you are no fool; you call yourself a fool, there's proof enough in
that!" -- Rostand, "Cyrano de Bergerac"

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019