RE: Checking XCOPY Exit Value in Cygwin Bash

2006-08-07 Thread David Christensen
Shane:
 Thank you for the tip. Actually I am using Visual Source Safe as the 
 Source Management tool.
 I was considering the use of CVS, but decided against at the last
 moment because most of the fellow developers including me, had been
 using VSS for a considerable amount of time, and felt that the
 migration from a VSS to CVS would take a some time. Similarly for
 Make. We are primarily a group of developers who are conversent with
 MS Windows than the Unix environment. Cygwin basically gives us the
 power of bash scripting and the ease of Windows at the same time. :)

Visual tools can give neophytes a boost, but typically become
cumbersome as complexity increases.  Command-line tools require more
learning effort up front, but scale better because they are completely
customizable.


I agree that integrating Visual Studio products, CVS, and/or Make is a
non-trivial undertaking.  (The roles tool smith and build meister
come to mind.)  But, I'm now learning C#, .NET, ASP.NET, Mono,
Apache/mod_mono, etc., and will be going through this process by
necessity. (I'd like to be able to write C# libraries and build/run
console and web applications on both Windows and Debian GNU/Linux).


 What I am trying to do is, checkout the source to the build directory 
 and if there are any local changes in my working directory copy them
 to the build directory, build and do a test run from there. This is
 so that I can test my code before I do the actual check in.

Make has RCS (and CVS?) integration features that allow it to do a
checkout/ update prior to a build.  However, I typically use the tools
separately, so I can control what happens when and see the results
before deciding what to do next.


David


--
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/



Checking XCOPY Exit Value in Cygwin Bash

2006-08-06 Thread Shane
Hi all,
   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. To copy only the updated files, I used the /D 
switch for XCOPY. 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. 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?

Thank you for your time.
Shane

--
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/



Re: Checking XCOPY Exit Value in Cygwin Bash

2006-08-06 Thread Igor Peshansky
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/
  |\  _,,,---,,_[EMAIL PROTECTED] | [EMAIL PROTECTED]
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/



Re: Checking XCOPY Exit Value in Cygwin Bash

2006-08-06 Thread Mark Fisher

On 8/6/06, Shane wrote:

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?


result codes are stored in $? in bash
success = 0 usually, and xcopy seems to follow the norm here.

here, i did
xcopy somefile somedir
echo $?

which returned 0

when i tried
xcopy nonfile somedir
echo $?

i get 4

so test for 0 for success.

extensions of this idea:
xcopy somefile somedir  echo ok
xcopy somefile somedir || echo fail

--
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/



Re: Checking XCOPY Exit Value in Cygwin Bash

2006-08-06 Thread Shane

Igor Peshansky wrote:

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.

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


  
Of course it didn't.  Please read a good bash tutorial, or the Special

Parameters section of the bash manpage.
  

Hi Igor and Mark,
   Thank you very much for the quick reply.

I was initially using 


tar -cf - `find $source_dir -name *.$file_ext -print` | ( cd $dest_dir  
tar xBf - )

but it had a problem with path names with spaces. Obviously being not that good 
in bash scripting, I couldn't get over that issue. So that was why I decided to 
use the XCOPY command. I will use your method and see. Thanks again.

I made a silly mistake in my former email. I was actually checking $? 
(not $!) for the exit code, but it didn't work. But I saw in a later reply from 
Mark that it worked for him. I will check it again. Maybe I was doing something 
silly.

thanks again 
Regards

Shane


--
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/



RE: Checking XCOPY Exit Value in Cygwin Bash

2006-08-06 Thread David Christensen
Shane wrote:
 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. To copy only the updated files, I used the /D switch for XCOPY.
 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.

There are standard software development tools that solve the problems
you are facing -- CVS and Make:

http://ximbiot.com/cvs/wiki/index.php?title=Main_Page

http://ximbiot.com/cvs/wiki/index.php?title=Main_Page


Both are included in Cygwin.  In the long run, you'd be better off
investing in a basic to intermediate understanding of both rather than
hacking together custom scripts to implement a subset of their
functionality.


David


--
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/



Re: Checking XCOPY Exit Value in Cygwin Bash

2006-08-06 Thread Shane

David Christensen wrote:

There are standard software development tools that solve the problems
you are facing -- CVS and Make:

http://ximbiot.com/cvs/wiki/index.php?title=Main_Page

http://ximbiot.com/cvs/wiki/index.php?title=Main_Page


Both are included in Cygwin.  In the long run, you'd be better off
investing in a basic to intermediate understanding of both rather than
hacking together custom scripts to implement a subset of their
functionality.

To David,
  Thank you for the tip. Actually I am using Visual Source Safe as the 
Source Management tool.
I was considering the use of CVS, but decided against at the last moment 
because most of the fellow developers including me, had been using VSS 
for a considerable amount of time, and felt that the migration from a 
VSS to CVS would take a some time. Similarly for Make. We are primarily 
a group of developers who are conversent with MS Windows than the Unix 
environment. Cygwin basically gives us the power of bash scripting and 
the ease of Windows at the same time. :)


What I am trying to do is, checkout the source to the build directory 
and if there are any local changes
in my working directory copy them to the build directory, build and do a 
test run from there. This is so that I can test my code before I do the 
actual check in.


To Igor,
  Your method worked perfectly for paths with spaces too. :) Now if 
only I had a way of detecting if files were updated or not.


To Mark
  I tried it again. Unfortunately echo $? gives 0 for both the cases 
of, number of files copied = 0 and, greater than 0.
  The link I posted from MSDN 
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true 
says that XCOPY returns 1 when there were no files to be copied.


So I guess I am back to square one. :(

Thanks and best regards
Shane


GET FREE 5GB ONLINE STORAGE - Safely store your documents, photos and music 
online!
Visit http://www.inbox.com/storage to find out more!

--
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/



Re: Checking XCOPY Exit Value in Cygwin Bash

2006-08-06 Thread Igor Peshansky
On Mon, 7 Aug 2006, Shane wrote:

 What I am trying to do is, checkout the source to the build directory
 and if there are any local changes in my working directory copy them to
 the build directory, build and do a test run from there. This is so that
 I can test my code before I do the actual check in.

As David said, cvs has an easy way of doing this (using cvs diff and
patch), which will also deal with local and checked in changes to the
same file (while your method won't).

 To Igor,
   Your method worked perfectly for paths with spaces too. :)

It was designed to. :-)

 Now if only I had a way of detecting if files were updated or not.

Did you happen to notice the mention of the --keep-newer-files tar
option in my original reply to you?  Just add that to the last tar, and
you will only copy the files that were changed in your copy (presumably by
you) after the checked in version.

 To Mark
   I tried it again. Unfortunately echo $? gives 0 for both the cases of,
 number of files copied = 0 and, greater than 0.
   The link I posted from MSDN
 http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true
 says that XCOPY returns 1 when there were no files to be copied.

MSDN apparently lies.  XCOPY for me returns non-zero on error, and 0 on
normal execution (no matter how many files were copied).

 So I guess I am back to square one. :(

There are quite a few POSIX and Unix tools that are much better for this
job than xcopy.  I'd say investing some time in a Unix tutorial now would
save you more effort in the long run.
HTH,
Igor
-- 
http://cs.nyu.edu/~pechtcha/
  |\  _,,,---,,_[EMAIL PROTECTED] | [EMAIL PROTECTED]
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/



Re: Checking XCOPY Exit Value in Cygwin Bash

2006-08-06 Thread Christopher Faylor
On Sun, Aug 06, 2006 at 07:46:07AM -0800, Shane wrote:
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.  To copy only the updated files, I used the /D switch for XCOPY.
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.  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.

Is there some reason why you are not using cp to accomplish your task?
cp --help should provide you with all sorts of options for copying files.
You should be able to press cp into service for this.

Using DOS utilities and DOS paths for this type of thing is putting you
on the fringes of support for Cygwin.  I really wouldn't recommend it.
Clearly this is not such a Windows-specific problem that it outside of
the capabilities of a UNIX solution.

cgf

--
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/



Re: Checking XCOPY Exit Value in Cygwin Bash

2006-08-06 Thread Shane

Igor Peshansky wrote:

As David said, cvs has an easy way of doing this (using cvs diff and
patch), which will also deal with local and checked in changes to the
same file (while your method won't).

  

Point taken. I will certainly look into it.

Did you happen to notice the mention of the --keep-newer-files tar
option in my original reply to you?  Just add that to the last tar, and
you will only copy the files that were changed in your copy (presumably by
you) after the checked in version.

  

Yeah I saw that reply and I had tried it. There were two problems.
   1. New files will not be added to the build directory. It will say 
something like
 tar: ./Test/res/Test.manifest: Warning: Cannot stat: No such 
file or directory

 tar: Current `./Test/res/Test.manifest' is newer
  and the required manifest file is not copied into the build 
folder. So for the initial copy I have to
  use it without the --keep-newer-files, and for the subsequent 
copies I will have to use the --keep-newer-files.


   2. This is the real problem. That is getting an indication whether 
none of the files were updated or not. I want to proceed 
with the rest of the building script only if more than one files have 
been copied. I do not know how to get that using the tar 
command. I tried echoing the $? value but it gives 0 all the time. The 
source compiler can
detect if the sources were updated or not, on it's own, but 
there are a lot of projects in one Visual Studio
Solution (about 60), that I can't wait until all those projects 
have been parsed.
   I am using  
   while read amount ; do


if [ ${amount::1} != 0 ]; then
copied=true;
fi
done  copy.log
for that purpose.


MSDN apparently lies.  XCOPY for me returns non-zero on error, and 0 on
normal execution (no matter how many files were copied).
  
If that is the case, then there is no point in trying to check for the 
xcopy return value.
As a short term solution I will stick with my original XCOPY solution. 
But I will try to find out
what CVS, Make and the other tools have to offer. If there is a way of 
getting if files have been replaced using the

tar command, I will try to implement that into my solution.
Although I am fairly competent at programming in C/C++, this is my first 
attempt in writing a serious bash script,

and I must admit that I am both impressed and overwhelmed by it's power. :)

Thank you all for the help offered so far.
Regards
Shane


GET FREE 5GB ONLINE STORAGE - Safely store your documents, photos and music 
online!
Visit http://www.inbox.com/storage to find out more!

--
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/



Re: Checking XCOPY Exit Value in Cygwin Bash

2006-08-06 Thread Shane

Christopher Faylor wrote:


Is there some reason why you are not using cp to accomplish your task?
cp --help should provide you with all sorts of options for copying files.
You should be able to press cp into service for this.

Using DOS utilities and DOS paths for this type of thing is putting you
on the fringes of support for Cygwin.  I really wouldn't recommend it.
Clearly this is not such a Windows-specific problem that it outside of
the capabilities of a UNIX solution.

  


My initial attempt was with cp. But I didn't see a way of preserving the 
original directory structure of the source dir,
inside the destination directory. XCOPY just seemed easier. Will have a 
go at 'cp' again.

Thanks and regards
Shane

--
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/



Re: Checking XCOPY Exit Value in Cygwin Bash

2006-08-06 Thread Christopher Faylor
On Mon, Aug 07, 2006 at 06:52:40AM +0900, Shane wrote:
Christopher Faylor wrote:
Is there some reason why you are not using cp to accomplish your
task?  cp --help should provide you with all sorts of options for
copying files.  You should be able to press cp into service for this.

Using DOS utilities and DOS paths for this type of thing is putting you
on the fringes of support for Cygwin.  I really wouldn't recommend it.
Clearly this is not such a Windows-specific problem that it outside of
the capabilities of a UNIX solution.

My initial attempt was with cp.  But I didn't see a way of preserving
the original directory structure of the source dir,

What's wrong with cp -a or cp -r?

--
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/



Re: Checking XCOPY Exit Value in Cygwin Bash

2006-08-06 Thread Shane
 What's wrong with cp -a or cp -r?
It only copied files that were directly under the source directory.
It didn't traverse the directories inside source recursively. I did some 
searching and,
I came up with a similar thread. Finally the tar method was recommended in it 
too.
Please refer : http://lists.samba.org/archive/samba/1999-December/016328.html 
and it's follow-ups.

Thanks and Regards
Shane


 -Original Message-
 From: [EMAIL PROTECTED]
 Sent: Sun, 6 Aug 2006 21:04:27 -0400
 To: cygwin@cygwin.com
 Subject: Re: Checking XCOPY Exit Value in Cygwin Bash
 
 On Mon, Aug 07, 2006 at 06:52:40AM +0900, Shane wrote:
 Christopher Faylor wrote:
 Is there some reason why you are not using cp to accomplish your
 task?  cp --help should provide you with all sorts of options for
 copying files.  You should be able to press cp into service for this.
 
 Using DOS utilities and DOS paths for this type of thing is putting you
 on the fringes of support for Cygwin.  I really wouldn't recommend it.
 Clearly this is not such a Windows-specific problem that it outside of
 the capabilities of a UNIX solution.
 
 My initial attempt was with cp.  But I didn't see a way of preserving
 the original directory structure of the source dir,
 
 What's wrong with cp -a or cp -r?
 
 --
 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/

--
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/



Re: Checking XCOPY Exit Value in Cygwin Bash

2006-08-06 Thread Christopher Faylor
On Sun, Aug 06, 2006 at 08:26:11PM -0800, Shane wrote:
 What's wrong with cp -a or cp -r?
It only copied files that were directly under the source directory.  It
didn't traverse the directories inside source recursively.  I did some
searching and, I came up with a similar thread.  Finally the tar method
was recommended in it too.  Please refer :
http://lists.samba.org/archive/samba/1999-December/016328.html and it's
follow-ups.

1999 archives in a non-cygwin mailing list?  No, thank you.

I have used cp -a and cp -r any number of times with success on
cygwin.  However, if cp is not working correctly, I'm sure the coreutils
maintainer would be interested in fixing it, if you have further
details.

cgf

--
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/