Running bash script from batch file

Open forum for end-user questions about Wine. Before asking questions, check out the Wiki as a first step.
Forum Rules
Locked
cpicds
Newbie
Newbie
Posts: 3
Joined: Tue Nov 29, 2011 4:25 am

Running bash script from batch file

Post by cpicds »

I am using the Keil uVision IDE under Wine. This has the option to run a user-specified batch file for special compilations. The batch file I have written determines whether it is running under Windows or Linux and, in the latter case, runs a shell script to perform the required action. (The shell script simply converts the file names from DOS to Linux and runs the same Java program to perform the work.)

This used to work. However, when I recreated by source tree anew from the VCS, it stopped working. The failure appears to be that it cannot find the shell script. (Both the batch file and the shell script have the executable flag set.) Adding debug output to the batch file shows that it is finding the shell script, but it still reports "file not found" when trying to execute it. (I have checked that the path has exactly the same case as the command.)

Code: Select all

@echo off
REM SHELL is defined under Wine, but not under Windows

if not "%SHELL%"=="" (
	echo "Linux"
	if exist ../utilities/h86crc/bin/javacrc.sh (
		echo "javacrc.sh exists"
		../utilities/h86crc/bin/javacrc.sh %1 %2 %3 %4
	) else (
		echo "javacrc.sh not found"
	) 
) else (
	echo "Windows"
	java %1 %2 %3 %4
)
The output is:

User command #1: ..\utilities\h86crc\bin\javacrc.bat -jar ..\utilities\h86crc\bin\H86CRC.jar -m:1024 H:\projects\atlasxml\AtlasMV\Bin\AtlasMV_NRIM01.H86
"Linux"
"javacrc.sh exists"
File not found

The first line of the shell script is an echo command and this does not appear.

Any help in resolving this would be very much appreciated.

Thanks.
vitamin
Moderator
Moderator
Posts: 6605
Joined: Sat Feb 23, 2008 2:29 pm

Re: Running bash script from batch file

Post by vitamin »

cpicds wrote:The shell script simply converts the file names from DOS to Linux
See http://wiki.winehq.org/winepath
cpicds
Newbie
Newbie
Posts: 3
Joined: Tue Nov 29, 2011 4:25 am

Re: Running bash script from batch file

Post by cpicds »

vitamin wrote:
cpicds wrote:The shell script simply converts the file names from DOS to Linux
See http://wiki.winehq.org/winepath
The shell script does that correctly. However, Wine is not running the shell script and simply reporting "File not found" - although it has already successfully found the file in the "if exists" statement.

For reference, the shell script is:

Code: Select all

#!/bin/bash
echo "javacrc.sh"
# Translates uVision file specification from Windows to Unix and
# executes Java command with translated names. Realpath is used
# because Java appears not to like the winepath output.
JARFILE="$(winepath "$2")"
HEXFILE="$(winepath "$4")"
JARFILE="$(realpath "$JARFILE")"
HEXFILE="$(realpath "$HEXFILE")"
java $1 "$JARFILE" $3 "$HEXFILE"
# Convert line ends to MS-DOS format (requires tofrodos package)
todos -u "$HEXFILE"
The echo statement output does not appear.
cpicds
Newbie
Newbie
Posts: 3
Joined: Tue Nov 29, 2011 4:25 am

Post by cpicds »

I have just found the problem.

The error message is very misleading. The problem is not that the file cannot be found, but that it has DOS style line ends (CR LF). It seems that our VCS, MS-SourceSafe, silently 'corrects' the Unix line ends to DOS ones. Hence everything worked initially, but failed when I checked out a clean copy of the file from the VCS.
Locked