Shell Command not working now

I have two bash files that USED to work, but now they don’t. I’ll post one so you can see the syntax:

#!/bin/bash
# Comment below for dev system...
wkhtmltopdf --quiet  /home/ian/Documents/The\ Nursery/Gift\ Certs/rcpts.html /home/ian/Documents/The\ Nursery/Gift\ Certs/rcpts.pdf

#html2ps Gift\ Certificate Gift\ Certificate.html | lp
lp -d EPSON_WF_7610_Series rcpts.pdf
rm -Rf rcpts.html
rm -Rf rcpts.pdf

Here is the code I have used to call it, keep in mind this worked at one time… but now it doesn’t.

// Variable declarations...
Var cmdPrn As String
Var shTerm As New Shell
Var strSystem As String = modSysFunc.mthSysId // Get current working system...

// Function(s)...
strSystem = strSystem.Trim // Trims any extraneous crap from the string...

Select Case strSource
Case "GiftCert"
  If( strSystem = "mcdians-devtop" ) Then
    cmdPrn = "/home/ian/Documents/The\ Nursery/Gift\ Certs/ConvertPrint.go" // Dev machine...
  ElseIf( strSystem = "jhgc-shoptop" ) Then
    cmdPrn = "/home/jhgc_staff/Documents/The\ Nursery/Gift\ Certs/ConvertPrint.go" // Prod machine...
  ElseIf( strSystem = "jhgctill-001" ) Then
    cmdPrn = "/home/jhgc-till/Documents/The\ Nursery/Gift\ Certs/ConvertPrint.go" // Main Till machine...
  Else
    MessageBox( "This function cannot work as you are not on a validated system." )
    Exit
  End If
  
Case "PlantInfo"
  If( strSystem = "mcdians-devtop" ) Then
    cmdPrn = "/home/ian/Documents/The\ Nursery/PDF/Plant\ Information/ConvertPrint.go" // Dev machine...
  ElseIf( strSystem = "jhgc-shoptop" ) Then
    cmdPrn = "/home/jhgc_staff/Documents/The\ Nursery/PDF/Plant\ Information/ConvertPrint.go" // Prod machine...
  ElseIf( strSystem = "jhgctill-001" ) Then
    cmdPrn = "/home/jhgc-till/Documents/The\ Nursery/PDF/Plant\ Information/ConvertPrint.go" // Main Till machine...
  Else
    MessageBox( "This function cannot work as you are not on a validated system." )
    Exit
  End If
  
Case "Rcpt"
  'MessageBox( "In the print comands now..." )
  If( strSystem = "mcdians-devtop" ) Then
    cmdPrn = "/home/ian/Documents/The\ Nursery/Gift\ Certs/ConvertPrintRcpt.go" // Dev machine...
  ElseIf( strSystem = "jhgc-shoptop" ) Then
    cmdPrn = "/home/jhgc_staff/Documents/The\ Nursery/Gift\ Certs/ConvertPrintRcpt.go" // Prod machine...
  ElseIf( strSystem = "jhgctill-001" ) Then
    cmdPrn = "/home/jhgc-till/Documents/The\ Nursery/Gift\ Certs/ConvertPrintRcpt.go" // Main Till machine...
  Else
    MessageBox( "This function cannot work as you are not on a validated system." )
    Exit
  End If
End Select

shTerm.Execute( cmdPrn )

If shTerm.ErrorCode <> 0 Then
  MessageBox( "This in the If part The exit code is: " + shTerm.ExitCode.ToString )
Else
  'MessageBox( "Error " + Str( shTerm.ErrorCode ) )
  'MessageBox( "This is in the Else part The exit code is: " + shTerm.ExitCode.ToString )
  shTerm.Execute( cmdPrn )
End If

The bash script will work if you click on the actual file or run it from command line but when I try to call it… and run it from my application… yeah… not so much.

My immediate reaction is that you’re calling items there with no path. Remember, Shells are not the same as a terminal in that there is little or no preconfigured environment.

The first thing to try is putting

set -x

At the 2nd line of the scripts and make your apps output the Shell results somewhere and make sure all of the commands are succeeding.

The second thing I’d try is to go to a terminal and type

which wkhtmltopdf

note the full path and try putting the full path in your script. If it works, you need to leave it or configure the environment before sending your commands.

1 Like

are that spaces in path or separated commands?

cmdPrn = "/home/jhgc-till/Documents/The\ Nursery/Gift\ Certs/ConvertPrint.go

cmdPrn is the command variable that am loading with the path /home/jhgc-till/Documents/The\ Nursery/Gift\ Certs/ then the last bit is ConvertPrint.go, which is my bash script I want triggered.

So I have the path defined as well as the script.

When you say set -x, where would I apply that?

Keep in mind that if I execute the actual script itself, it works. The html file is converted to PDF then printed to the called printer. But what is not happening is when I try to execute the same script from within my application (which worked before and works in another application I have, using the same script and command to execute) the script never fires off.

This is where I am uncertain of what is going on. My dev system has not changed nor has my production system. The only change is the till machine and that was added recently as a replacement to the production system as soon as I finish getting everything ironed out.

/home/jhgc-till/Documents/The\ Nursery/Gift\ Certs/

The path has spaces in the names eg: The Nursery is below Documents so in order for the terminal to understand The Nursery is one folder/directory I have to use the \ to denote end of text start of space: The\ Nursery.

Terminal Paths

ahh, so its a linux special. i only know “” around or underscore in windows world.

can you read any error output from shTerm in Xojo?

Nope, the code I wrote to execute the script returns a 0 which is *nix for success. When I execute the script by either CLI or clicking on the bash file, it runs fine.But when I use the ```
shTerm.Execute( cmdPrn ) to execute the script, it returns a success message but nothing happens.

What is bothering me is this same set up worked fine before, but now … nope.

i meant this
https://documentation.xojo.com/api/os/shell.html#shell-readall
i never used it but it saw it and looks interesting for my raspberry pi hobby projects with Python scripts.
seems that sh.Result is also all the output after execute. i guess that is where you get just a 0.
i read that it works before but maybe you get a answer from shell to understand the issue in this xojo version.

Yup, I got that. What I’m talking about is the paths to the commands themselves. Your script calls wkhtmltopdf without any path info. You can do that in a terminal because the environment is set up with a series of paths in which to look for that app. No such path lookup exists in Shell by default.

Just after the first line of your script, but before your code

#!/bin/bash
set -x

Right, which is why I asked for the output. After this line:

shTerm.Execute( cmdPrn )

Put

Dim s as String = shTerm.Result

Put a breakpoint after that and run the app. Result will contain any output that was returned from your script running and I’d bet it will tell you exactly what the problem is.

1 Like

that is not the same as the response from the executed shell.
see gregs example & suggesttion.

If shTerm.ErrorCode <> 0 Then

your example at top just do this

shTerm.Execute( cmdPrn )

if a command can not do his task i would expect an output.

Right. If your bash script doesn’t explicitly exit with a code, it’ll always return 0, regardless of if there were any errors in your script.

Now, in addition to the set -x I suggested, you could also add set -e which will cause your script to exit with an error code if one of the commands in the script fails.

Not knowing how your GO scripts are configured, is it possible that your GO language interpreter has a special environment entry in your interactive environment that is not being set in the Xojo Shell?

What does the shebang entry look like in the GO scripts? Are you using this:

#! /usr/bin/env gorun