terminal commands not working in shell

Hi there - this a MAC question…
I was under the impression that terminal commands would work under shell.
f(1) is the folder item

all these commands in the shell execute perfectly when I do them in the terminal…
Am i missing something?

Cheers,
Sean

maybe I need to put these into some kind of script and then run that from the shell (I used a bat file in window which worked perfectly.)
What would it be? I’m not really used to the mac scripts so if somebody could point me in the right direction :slight_smile:

here’s the code
f(1)= specialfolder.applicationdata.child(“Guitar SightReader Toolbox”).child(“ABC”).child(“MACconvert”)

dim sh as shell
sh.Mode = 0
sh.TimeOut = 60000 ’ 1 minute
sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+" chmod +x abcm2ps"
sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+" chmod +x abc2midi"
sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+"./abc2midi chunk1.abc"
sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+"./abc2midi chunk2.abc"
sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+"./abc2midi chunk3.abc"
sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+"./abc2midi chunk4.abc"
sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+"./abc2midi chunk5.abc"
sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+"./abc2midi chunk6.abc"
sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+"./abc2midi chunk7.abc"
sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+"./abc2midi chunk8.abc"
sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+"./abc2midi SReadermusic.abc"
sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+"./abcm2ps -v -s 0.6 -B2 SReader.abc"
'sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+" java -jar batik-rasterizer.jar out001.svg"
sh.Execute chr(34)+f(1).AbsolutePath +chr(34)+“qlmanage -t -s 1000 -o . Out001.svg”

In the terminal this would produce mid files for the chunk files as well as SRreadermusic.abc
it would produce an SVG file from SReader.abc
qlmanage -t -s 1000 -o . Out001.svg would change that svg to a png (Out001.svg.png)

but not with that code above
Cheers,
Sean

I find it’s easier to use .shellPath, and I’m not used to seeing how your commands are formatted.

I would also wrap it in a way where you can do error checking.

[code]Dim commands(-1) as string
commands.append "/bin/chmod +x "+f(1).shellPath+“abcm2ps”

commands.append "qlmanage -t -s 1000 -o "+f(1).shellPath+"Out001.svg"

Dim n,l as integer
Dim result as string
Dim s as new shell
n = ubound( commands )
for l=0 to n
s.execute commands( l )
result = trim( s.result )
if result <> "" then msgbox result
next[/code]

I've not checked it, just written it out above, but hopefully it will be enough to get you going.

Many utilities rely on environment variables, which are set in the terminal, but may not be set in a Shell process. Shells run in a minimal environment. You need to set up any environment variables your command needs.

Also, do not rely on the “current working directory” being set correctly either. Always use full paths. You might be better off writing out a script file and then executing that in the shell.

I actually did that … I followed a tutorial and, using text edit, created a script that (called Goforit.sh).
Now when I run it from the terminal, it works perfectly.
The tutorial recommended that before running it i need to input
sudo chmod 700 Goforit.sh
which i did and it ran great when I typed in ./Goforit.sh

HOWEVER, now I cannot seem to run the script from Xojo. Am I doing this wrong?
Also, if somebody install my app on their computer, would I need to add
sudo chmod 700 Goforit.sh
as shell.execute in order to run my script?

I have
dim fff as FolderItem=specialfolder.applicationdata.child(“Guitar SightReader Toolbox”).child(“ABC”).child(“MACconvert”)
sh.Mode = 0
sh.TimeOut = 60000 ’ 1 minute
sh.execute chr(34)+fff.NativePath+"/./Goforit.sh" +chr(34)

and my Goforit.sh is like this:

chmod +x abcm2ps
chmod +x abc2midi
./abc2midi chunk1.abc
./abc2midi chunk2.abc
./abc2midi chunk3.abc
./abc2midi chunk4.abc
./abc2midi chunk5.abc
./abc2midi chunk6.abc
./abc2midi chunk7.abc
./abc2midi chunk8.abc
./abc2midi SReadermusic.abc
./abcm2ps -v -s 0.6 -B2 SReader.abc
qlmanage -t -s 1000 -o . Out001.svg

/./ is wrong. Examine fff.NativePath to see if it already has a trailing slash and either add one or just append “Goforit.sh”

Ok -it doesn’t have a slash.
From what I see, it actually does run it (I msgbox the sh.result)
The problem is that it states that
it says that this files that are in this directory do not exist.
the native path for fff is /Users/seanclancy/Library/Application Support/Guitar SightReader Toolbox/ABC/MACconvert
me adding “/./Goforit.sh”
Does it mean that it is looking in the wrong directory for these files?
If I go to terminal and go into the Macconvert folder and run ./Goforit.sh it works perfectly…
What am I missing?

chmod: abcm2ps: No such file or directory
chmod: abc2midi: No such file or directory
/Users/seanclancy/Library/Application Support/Guitar SightReader Toolbox/ABC/MACconvert/./Goforit.sh: line 3: ./abc2midi: No such file or directory
/Users/seanclancy/Library/Application Support/Guitar SightReader Toolbox/ABC/MACconvert/./Goforit.sh: line 4: ./abc2midi: No such file or directory
/Users/seanclancy/Library/Application Support/Guitar SightReader Toolbox/ABC/MACconvert/./Goforit.sh: line 5: ./abc2midi: No such file or directory
/Users/seanclancy/Library/Application Support/Guitar SightReader Toolbox/ABC/MACconvert/./Goforit.sh: line 6: ./abc2midi: No such file or directory
/Users/seanclancy/Library/Application Support/Guitar SightReader Toolbox/ABC/MACconvert/./Goforit.sh: line 7: ./abc2midi: No such file or directory
/Users/seanclancy/Library/Application Support/Guitar SightReader Toolbox/ABC/MACconvert/./Goforit.sh: line 8: ./abc2midi: No such file or directory
/Users/seanclancy/Library/Application Support/Guitar SightReader Toolbox/ABC/MACconvert/./Goforit.sh: line 9: ./abc2midi: No such file or directory
/Users/seanclancy/Library/Application Support/Guitar SightReader Toolbox/ABC/MACconvert/./Goforit.sh: line 10: ./abc2midi: No such file or directory
/Users/seanclancy/Library/Application Support/Guitar SightReader Toolbox/ABC/MACconvert/./Goforit.sh: line 11: ./abc2midi: No such file or directory
/Users/seanclancy/Library/Application Support/Guitar SightReader Toolbox/ABC/MACconvert/./Goforit.sh: line 12: ./abcm2ps: No such file or directory
Testing Quick Look thumbnails with files:
Out001.svg
[ERROR] Can’t access file://localhost/Out001.svg: The file “Out001.svg” couldn’t be opened because there is no such file.

  • No thumbnail created for /Out001.svg
    Done producing thumbnails

Correct. It cannot find the files, because it is not starting in the same directory where the files are. Add a CD to your script to put it in the correct directory. Or use full path names to the files, instead if ./abc2midi

The first rule of scripting is: “Make no assumptions.” Always specify everything as explicitly as you can.

And collapse “/./” to simply “/”. You don’t need the extra dot in your path. It just happens to work, but it is still wrong.

As Tim suggest, the Xojo shell requires the full ‘shell’ path to the terminal commands and also to the files that you want the console app to work on.

Are you intending to ship this app on the Mac App Store?

Hi,

Sam and Tim are right. I struggled with an unrar command line utility. Everything ran fine in terminal, but not from my app.
Solution was to add the full path to the cl utility AND the file it uses, converted with .ShellPath and trailed with a slash.

So in my situation the command line was 'unrar x [rarfile] [destination], which ran fine in terminal, but for the Xojo command line I had to supply the fullpath as follows: [full path] + ‘unrar x’ + [full path] + ‘rarfile’ + [full path] + ‘destination’. Don’t forget to add spaces and/or slashes. That worked fine. Inspect the results from the command line.

Well - I got the script going when I added a
cd /user/ etc… (using "\ " instead of " ")
I was very happy.

Then I realized that I would need to change that cd command for other computers.
So I created a textfile in the directory that would add the user’s computer for the cd comand.
so far so good.
I ran it - permission denied.
I realized I was going to need to do
sudo chmod 700 Goforit.sh
f here is a folder item pointing directly at Goforit.sh
it doesn’t work…
It cam back with the result saying that the file didn’t exist (it showed the correct full path to)
I know it exists! It lied to me!

how would i need to change the following code for it to work.

dim s as new shell
s.Execute chr(34)+"sudo chmod 700 "+f.NativePath+chr(34)
msgbox s.result

As for the App store, probably yes - although I haven’t reached that far yet. I’ve been working on this app for 3 1/2 years and it’ll be the best guitar/bass training software on earth :slight_smile:
I’m aware that you need to pay for a developer’s license to have your apps on the Apple app store right?

You may want to investigate a different method of accomplishing this task, In order to include a console app with your main application, you’re going to have to Sandbox it and your application, which leads to a whole bag of hurt. You should check out the discussions on using NSTaskMBS before going any further. The console application will have to be included in your application bundle.

Apple’s Sandboxing security mechanism (which is required for the Mac App Store), is incredibly restrictive.

Well, I plan not to. If I can get a solution for doing this sudo command, Everything will be as it should with my app :slight_smile:
Anybody else with a solution for this?

As an alternative, you can change your shell command from

sh.execute “/path/to/Goforit.sh”

to

sh.execute “sh /path/to/Goforit.sh”

or

sh.execute “bash /path/to/Goforit.sh”

Ie., pass your script directly to shell instead of relying on the system to do it for you by setting the execute bit.

Hi Tim,
I tried both methods .i.e
dim ffff as FolderItem=specialfolder.applicationdata.child(“Guitar SightReader Toolbox”).child(“ABC”).child(“MACconvert”)
’ the file where Gofor.sh resides
sh.Mode = 0
sh.TimeOut = 60000 ’ 1 minute
'sh.execute “bash /”+ffff.NativePath+"/to/Goforit.sh" 'I tried both of these
sh.execute “sh /”+ffff.NativePath+"/to/Goforit.sh"
I get the result
sh: //Users/seanclancy/Library/Application: No such file or directory

still no dice… is ffff.nativepath could to use for the shell - or should I do the path by
a=ffff.nativepath
a=a.replaceall(" “,”/ "
and use a for the path? And that doesn’t work either… like above it says file not found
when I run this using a for the path I get the result
sh: //Users/seanclancy/Library/Application Support/Guitar SightReader Toolbox/ABC/MACconvert/to/Goforit.sh: No such file or directory

I really appreciate your help…

Solving this one line of code will be the completion of 3 1/2 years of work!

Don’t add a leading slash to nativepath. “//Users” means something very different that “/Users”. No offense, but you don’t seem to be very experienced with unix. A little extra study of the OS might help a lot. There’s only so much that Xojo can abstract for you.

You’re right - this was a breeze in Windows (using a bat file).

So the long form is
“bash /Users/seanclancy/Library/Application\ Support/Guitar\ SightReader\ Toolbox/ABC/MACconvert/Goforit.sh/to/Goforit.sh”
if I can get the long form working then everything will be cinch…

Is the syntax for the “to” right?

[quote]dim ffff as FolderItem=specialfolder.applicationdata.child(“Guitar SightReader Toolbox”).child(“ABC”).child(“MACconvert”)
’ the file where Gofor.sh resides[/quote]

If that is truly the folder where the script file resides, then what is “to”???

IMO, it would be easier to point the folderitem to the script file itself (keep using .Child to get there), and then use ShellPath:

sh.Execute fff.ShellPath

yes - this definitely accesses the file - but it brings us back to original problem.
Permission denied. That’s why I need to
sudo chmod 700
this Goforit.sh. I had to do this when I used the terminal

I know that messing around with sudo is bad “Practice” but what is the point if a script cannot be accessed via shell?

Could you fling me simple line of code that would allow me to sudo chmod 700 this Goforit.sh file using fff.shellpath which points exactly to the file itself?

You shouldn’t need sudo to chmod the file. But again, you can pass the file to sh or bash (or csh or ksh or whatever shell you desire). I dropped that in my last post above.

sh.Execute "sh "+ fff.ShellPath