Using tty: in shell command

I need to run a MacOS shell to call a command to process a very short snippet of text. I could save the text from my Xojo app as a text file and use that as input, but I recall that in Unix you can specify the input file as tty: and then send the text directly following the command. But when I try this in the Terminal application, it tells me “tty: not found.” Is it possible to do this, and if so what is the correct syntax?

As an aside, what kind of processing?

The Shell object in Xojo is not the same as a Terminal window you get when you open the Terminal app
Terminal runs a pile of shell initialization code that the Shell object does not

I’m using pdflatex to format a math expression.

Norman, I haven’t tried this in a Xojo shell yet, just in Terminal. I figured that if I could get it to work in terminal first, then I’d try making a Xojo shell.

I should mention that it works fine in Terminal if I put the latex markup text in a text file and then use that as input. I’d just like to avoid dealing with a file if I don’t have to.

Will it take input from StdIn or perhaps as a command line parameter?

or a here file

I didn’t try stdin, but I just tried the Here File method using the
<<< ‘myMarkupCodeText’
format, and it works in Terminal (bash). Now, I’ll have to find out if it will work in a Xojo shell. I remember there’s been quite a bit of discussion here on the forum about the differences between running things in terminal and a Shell object. I’ll see what happens.

My biggest concern had been that the default output directory is the same as the input file. So, I wasn’t sure where it would put the output if there was no input file directory. It just puts the output in the user’s root directory. I think I can probably add some parameters to the command line to put the output in a more suitable place.

Anyway, so far so good. I’ll report back later with the Shell results. Thanks for the suggestions.

Preceding the command with cd works too.

Yeah, I figured the output destination shouldn’t be too difficult.

If this gets to be too easy, I have ways of making it more difficult. For example, it would be even nicer if I could avoid creating the output file as well, and just pipe the output into an http stream, and display it in an html viewer.

It didn’t take much effort to get it working as a Xojo shell. The only difference between it and the Terminal app was that I had to specify the path for the pdflatex command. As Kem suggested, I started with a CD command to set the directory to SpecialFolder.ApplicationData.MyAppStuff. Then the output file goes there when pdflatex is run. So, I just had to add some code to load the output file into my app.

Unfortunately, since pdflatex creates a pdf file, the only way to display it is to use an html viewer control, which isn’t very good for this kind of thing. I’ll have to see what other tools are in the MacTex package. I’m hoping there’s something that will produce a simple graphic file.

With a bit more experimentation, I found that pdflatex has a dvi format file output option, and there is also a utility dvipng (also part of the TexLive distribution) that converts dvi files to png graphics files. So, I’ve now got the shell generating and importing the png from LaTeX markup code. The png file is much easier to deal with.

Function LaTeX2pic(mTxt As String, res As Integer) as Picture
'Convert a LaTeX format math formula string to a picture
'mTxt is the LaTeX text
'res is the required picture resolution in dpi
'Uses a shell to call pdflatex and dvipng commands
'which are part of the MacTex/TexLive distributions
'
'cmdPath is the path to the directory of the Tex commands.
'Depending on which Tex distribution and which hardware/OS platform
'is used this line may need to be changed.
dim cmdPath As String = "/usr/local/texlive/2018/bin/x86_64-darwin/"
dim f As FolderItem = SpecialFolder.ApplicationData.Child("MyAppStuff")
if not f.Exists then
'Create Application Support/MyAppStuff folder if it doesn't already exist.
f.CreateAsFolder
end if
dim sPath As String = f.NativePath
Dim My_Shell As New Shell
My_Shell.TimeOut=-1
Dim theShellCode As String = "cd """+sPath+""""+EndOfLine
theShellCode = theShellCode + cmdPath+"pdflatex -output-format=dvi <<<'"
theShellCode = theShellCode + "\\documentclass[12pt]{slides}"+EndOfLine
theShellCode = theShellCode + "\\usepackage{geometry}"+EndOfLine
theShellCode = theShellCode + "\\usepackage{lingmacros}"+EndOfLine
theShellCode = theShellCode + "\\usepackage{tree-dvips}"+EndOfLine
theShellCode = theShellCode + "\\usepackage[usenames]{color} %used for font color"+EndOfLine
theShellCode = theShellCode + "\\usepackage{amssymb} %maths"+EndOfLine
theShellCode = theShellCode + "\\usepackage{amsmath} %maths"+EndOfLine
theShellCode = theShellCode + "\\usepackage[utf8]{inputenc} %useful to type directly diacritic characters"+EndOfLine
theShellCode = theShellCode + "\\geometry{papersize={8.5in,1.5in}}"+EndOfLine
theShellCode = theShellCode + "\\begin{document}"+EndOfLine
'Insert latex math code here. Warning: It must not contain any single quote characters.
theShellCode = theShellCode + mTxt+EndOfLine
'End of math code
theShellCode = theShellCode + "\\end{document}'"+EndOfLine
theShellCode = theShellCode + cmdPath+"dvipng -bg Transparent -D "+str(res)+" texput.dvi"+EndOfLine
My_Shell.Execute theShellCode
'If everything went according to plan, there should be a png file in the app's app support folder.
dim picFile As FolderItem = f.Child("texput1.png") 'default png file name
If picFile <> Nil Then
Dim pic As Picture
pic = Picture.Open(picFile)
'Optionally, place the picture directly in the window with either of the following commands uncommented:
'ImageWell1.Image = pic
'Canvas1.Backdrop = pic
Return pic
Else
'Error - Couldn't open picFile
return nil
End If
End Function

I’m sure there’s probably a way to set up the command search path so that it’s not necessary to use the full path to the commands, but I’m not familiar enough with Unix to know how to do this.