LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-03-2012, 05:09 AM   #1
sarenace
Member
 
Registered: Feb 2012
Posts: 57

Rep: Reputation: Disabled
Making windows executable cygwin scripts


Hi guys,
My newest problem comes from somewhat left field. My financial backer asked me to write a script for another one of his students. With all you guys have taught me, I found the job easy enough; the commands are

Quote:
awk 'FNR==2{split($2, a, "[\$\/]")}
FNR==3 && $1 ~ /180/{winnings+=b[2]; buyin+=a[2]+a[4]}
/Username/{split($(NF-1), b, "\$")}
END{print "Profit "winnings-buyin}' TS* >180man.txt
And

Quote:
awk 'FNR==2{split($2, a, "[\$\/]")}
FNR==3 && $1 ~ !/180/{winnings+=b[2]; buyin+=a[2]+a[4]}
/Username/{split($(NF-1), b, "\$")}
END{print "Profit "winnings-buyin}' TS* >MTT.txt

However, these individuals are busy people and dont want to have to download cygwin, or muck around with the command line. Is there a way of compiling these so that they come out as a windows executable file? Something that they just place in the folder containing the files of interest, double click and the script runs as written? Help would be much appreciated.

Last edited by sarenace; 05-03-2012 at 05:10 AM. Reason: oops, published the students username by mistake. Not meant to make that public
 
Old 05-03-2012, 06:54 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 19,526

Rep: Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608
I would rather download an awk binary for windows and put it next to the scripts. http://gnuwin32.sourceforge.net/packages/gawk.htm
 
Old 05-03-2012, 08:39 AM   #3
sarenace
Member
 
Registered: Feb 2012
Posts: 57

Original Poster
Rep: Reputation: Disabled
How do I do that? I would like instructions, im very new to this stuff.
 
Old 05-03-2012, 08:42 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 19,526

Rep: Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608
first try to download this awk and test your scripts (if they work properly with this awk).
second make cmd files which contain the script (as quoted) and able to run on windows.
 
Old 05-03-2012, 08:46 PM   #5
sarenace
Member
 
Registered: Feb 2012
Posts: 57

Original Poster
Rep: Reputation: Disabled
kk, i dl'd the gawk for windows package, and wrote a file containing the text

Quote:
C:\Program Files (x86)\GnuWin32\bin\gawk-3.1.6 myawkscript
and named the file 180man.cmd. It didn't work, but what is beginning to occur to me is that this solution will only work for awk scripts. If i ever want to do some work for them that involves a command line tool other than awk, I will be back to square 1. Does anyone know of a tool that compiles simple awk scripts to make standalone windows executable's? Failing that, If i could get them to download cygwin, could i make a file that when double clicked, opens an instance of cygwin, runs the script from within its folder, and then closes again?
 
Old 05-04-2012, 02:58 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 19,526

Rep: Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608Reputation: 6608
What was the problem with that cmd file?
Probably you need to use ":
"C:\Program Files (x86)\GnuWin32\bin\gawk-3.1.6" myawkscript

here is a compiler: http://www.tasoft.com/tawk.html
 
Old 05-11-2012, 05:28 AM   #7
sarenace
Member
 
Registered: Feb 2012
Posts: 57

Original Poster
Rep: Reputation: Disabled
Ok guys, I'm back, been too busy to check in on this thread the last few days and seen it hasn't moved. How about I make the question simpler; how would I make a batch file that when double clicked runs a cygwin command, assuming cygwin has already been installed? I would really like help on this issue.
 
Old 05-11-2012, 05:57 AM   #8
sarenace
Member
 
Registered: Feb 2012
Posts: 57

Original Poster
Rep: Reputation: Disabled
Alright, I have approached the problem thusly- I created a notepad file with the command

Quote:
awk 'FNR==2{split($2, a, "[\$\/]")}
FNR==3 && $1 ~ /180/{profit+=(b[2]-a[2]-a[4])}
/Username/{split($(NF-1), b, "\$")}END{print "Profit = " profit}' TS* > 180man.txt
and saved as 180man.sh. I then performed the command dos2unix on the file. I then copied the file into my cygwin /bin directory. From the terminal, I performed the command

chmod a+x 180man.sh

I then returned to my working directory, and typed 180man.sh, and got the following error message

Quote:
/usr/bin/180man.sh: line 3: $'\357\273\277awk': command not found
Which is absolutely mystifying. Does anyone have any idea whats going on here????
 
Old 05-11-2012, 06:11 AM   #9
sarenace
Member
 
Registered: Feb 2012
Posts: 57

Original Poster
Rep: Reputation: Disabled
Ok, I have tried to reduce the command to 3 and finally 1 new line; I get the error message each time, meaning something in the command is being interpreted as $'\357\273\277awk'; and I have no idea why. Has anyone else seen this behaviour from cygwin? Why would it interpret the command in the shell script to read what it does above? When I open the file in notepad I still see the awk command I have written up as per normal.
 
Old 05-11-2012, 09:41 PM   #10
sarenace
Member
 
Registered: Feb 2012
Posts: 57

Original Poster
Rep: Reputation: Disabled
Alright, have just tried the process again with a completely different command

Quote:
awk 'FNR==15 {Username=$3}
{gsub(/\$/," ",$0); gsub(/\+/,"",$0)}
FNR==1 || $0 ~ Username && /re-buys/{cost+=$6+$7+$8}
$0 ~ Username && /finish|win/ {winnings+=$7+$10}END{print "profit = " winnings-cost}' HH*
and got exactly the same error message

Quote:
/usr/bin/winnings.sh: line 4: $'\357\273\277awk': command not found
Does anyone have any idea whats going on?
 
Old 05-11-2012, 11:05 PM   #11
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Quote:
Originally Posted by sarenace View Post
Does anyone have any idea whats going on?
Yes. The crappy text editor you used to create the script inserted a byte order mark at the start of the file. You need to remove it, or use another editor.

The Unicode code for the BOM is U+FEFF. In UTF-8 encoding, it uses three bytes, 239 187 191 (decimal), which can be also written as \357\273\277 (octal) or \xef\xbb\xbf (hex).

Easiest way to remove the BOM from winnings.sh is to run
Code:
LANG=C LC_ALL=C sed -e 's|\xef\xbb\xbf||g' -i winnings.sh
The command will remove it from anywhere in UTF-8 text, but that's intentional. Although the BOM is only "allowed" at the start of the file, Windows utilities seem to sprinkle them willy-nilly; better remove them altogether.

You can use awk to remove BOMs and convert newlines to the Unix flavour at one go:
Code:
LANG=C LC_ALL=C awk 'BEGIN { RS="[\t\v\f ]*(\r\n|\n\r|\r|\n)" ; FS="[\r\n]" } { line = $0 ; gsub(/\xef\xbb\xbf/, "", line) ; printf("%s\n", line) }' input-file(s)... > output-file
but note that it does not edit the original file, it creates a fixed copy.
 
1 members found this post helpful.
  


Reply


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
Executable cygwin script in windows sarenace Programming 2 02-12-2012 03:14 AM
encrypted executable scripts izghitu Linux - Security 7 11-04-2010 02:17 PM
[SOLVED] running shell scripts in Windows XP with Cygwin leeelson Linux - General 2 04-26-2010 09:58 AM
Shell scripts in Windows Cygwin Micro420 Programming 14 10-17-2009 12:25 PM
How to write a batch file for windows that starts cygwin tool and runs unix scripts plasya777 Programming 5 05-04-2009 08:53 AM

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

All times are GMT -5. The time now is 11:46 PM.

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