Skip to Content
0

isql generates empty output file

Feb 05, 2017 at 12:23 PM

232

avatar image

Hello,

I am trying to connect to a Sybase ASE 15.7 data server in bash on Red Hat with isql the following way:

isql -S host.domain:port -U myLogin -P myPassword -i input.sql -o output.txt

input.sql contains the following text:

use master

go

select count(*) from syslogins

go

output.txt is being generated but unfortunately it is all empty.

If I run the exact same command in cmd.exe on Windows it generates output.txt with the actual result set:

-----------

83

(1 row affected)

How could I make isql work in bash so it does not generate empty output file but one with the actual result?

Permissions on input.sql are OK, it has 700 on it.

Thanks in advance.

Laszlo

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Bret Halford
Feb 05, 2017 at 03:44 PM
2

The usual reason for an empty output file in this sort of situation is isql not seeing a valid batch terminator
after the statement that should produce the output, causing isql to simply exit without any error. Most
other situations result in at least some error message in the output file.


I see that you do have a final "go" in your script, but perhaps something isn't quite right.
The "go" must start on the first character on the line, and there should be a newline character
after it (though there can be whitespace, comments, etc)

Examine the input file with "od -x input.txt" to see exactly what is on the line with the final "go"

Try adding a blank line after the final go.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Ahhh, good reminder.

Might be of interest to see where the input.sql file came from; Windows and *nix have different EOL characters for text files so if the file's not copied/converted properly (between Windows/*nix) then the different EOL character can cause the SQL script to behave as if there's no 'go' statement.

As another/quick check the OP could, on linux, run 'dos2unix input.sql' (converts Windows EOL characters to *nix EOL characters) to make sure the linux version of the file has a valid EOL character after the 'go' statement.

Alternatively, while on linux create a new file (eg, input2.sql), and submit this to isql. If this generates the desired output then the OP could run 'od -c <filename>' against both input*.sql files to see the difference in EOL characters (look for \n and \r characters).

1
Mark A Parsons Feb 05, 2017 at 03:02 PM
1

Try running your isql test again but this time remove the '-o output.txt' clause; this will cause all output to go to stdout and stderr (ie, to your console window).

With the '-o output.txt' clause removed, do you get the desired output? do you get any errors/output?

Share
10 |10000 characters needed characters left characters exceeded
Pankaj K Pathak Feb 07, 2017 at 01:26 PM
1

Hi https://answers.sap.com/users/27746/laszlo.html ,

Notepad++ is having issue of adding junk characters , so better to use Notepad (provided by MS) or vi(*nix default editor).

Thanks

Pankaj

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Check if utilities dos2unix and unix2dos allow you to convert text file contents to the OS platform you want to use.

This is typically the "control-M" character which is not visible when you take a dos file to unix and try to use it "as is"

HTH

Avinash

1
Laszlo Csorba Feb 05, 2017 at 05:30 PM
0

Bret, Mark,

Thanks very much for your comments, I appreciate it.

You were right, the issue was with the end of line characters \r\n which is now set to \n. Should start using vi more instead of Notepad++ / SFTP on Windows :).

Now that this works fine, I can start adding more complex code into input.sql as per my original intention.

Thanks again.

Regards,

Laszlo

Share
10 |10000 characters needed characters left characters exceeded