We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

How to use shell from basic macro (solved) [closed]

asked 2017-02-06 21:28:51 +0200

Pansmanser gravatar image

updated 2017-02-09 15:36:39 +0200

Having trouble making the SHELL call work from basic macro. I have a bash file hsf.sh that runs gnuplot, to load a control file and plot a data file. It needs no other input or control. Andrew Pitonyak makes it look easy, but I cannot get the SHELL call to do anything useful.

sFileName = sLocation & "hsf.sh"
i = shell(sFileName)
print i

Exit code is 0 implying success, but nothing happens. I've also tried variations (with appropriate file names):

i = shell ("gnuplot",,sFileName)
i = shell("/usr/bin/gnuplot",1, sFileName,true)
i = shell ("bash", 1, sFileName,true)

Perhaps I should shell to the the terminal, but I'm not sure how to do that.

Any suggestions what I am doing wrong?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-09-24 12:39:08.213567


What do think should happen? … poor old basic isn't able to plot something

karolus gravatar imagekarolus ( 2017-02-06 21:46:46 +0200 )edit

No, indeed. I am trying to export results to gnuplot and run that from the macro.

Pansmanser gravatar imagePansmanser ( 2017-02-07 22:05:54 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-02-07 15:26:54 +0200

Ratslinger gravatar image

updated 2017-02-07 22:56:23 +0200

If I read your question correctly, the following works on Mint 18:

Shell "bash -c 'sh /home/YOUR_DIRECTORY/TestSH.sh'"

Just a couple of other different Shell commands. This one opens the file in text editor:

Shell "bash -c 'xed /home/YOUR_DIRECTORY/TestSH.sh'"

Dictionary lookup through Firefox:

sString = "Hello"
Shell "firefox http://www.thefreedictionary.com/" & sString


Sub used in Calc to run these commands:

Sub shellTest
    Cell = oSheet.GetCellRangeByName("A1")
    ipAddr = Cell.getString

    'Works on Mint 18 to open root terminal'
    'Shell ("gksu /usr/bin/x-terminal-emulator",4)'

    'This line works - redirects output to .txt file'
    'Shell "bash -c 'xed /home/linuxnow/a/testSH.sh'"

    'Same as previous with a return code'
    x = Shell ("bash -c 'xed /home/linuxnow/a/testSH.sh'")
    MsgBox x
    'This works on Mint 18'
    'Shell "bash -c 'sh /home/linuxnow/a/TestCurlSH.sh'"
    'Works on Mint 18'
    sString = "Hello"
    Shell "firefox http://www.thefreedictionary.com/" & sString

    'Shell "firefox https://ask.libreoffice.org/en/questions/"'
end Sub

Also added another text edit showing Shell with return code.

edit flag offensive delete link more


OK, but these are bash command lines. I am trying to use shell out of lo basic.

Pansmanser gravatar imagePansmanser ( 2017-02-07 22:05:56 +0200 )edit

That is not true. These are straight out of a basic Sub. Each is a line in BASIC. The first should work with your hsf.sh mentioned in the question. My example actually contacts a weather service for a file download.

Ratslinger gravatar imageRatslinger ( 2017-02-07 22:17:58 +0200 )edit

My sincere apologies,Ratslinger. I was not familiar with that form of the shell call, only shell(command ...). I am about to try your suggestions, but wanted to correct my mistake first. I am working with LO 5.1 on Ubuntu 16.04. The macro is called from base, but makes no use of the datasource (yet).

Pansmanser gravatar imagePansmanser ( 2017-02-07 22:57:45 +0200 )edit

Apology not necessary - I just got a bit ticked you didn't even try it. BTW as in the sample, if you want a return code you must include the open & close parentheses Shell(command) otherwise you will get an error.

Ratslinger gravatar imageRatslinger ( 2017-02-07 23:15:32 +0200 )edit

Thanks, Ratslinger. The first produces 'file not found', but without gksu it opens the terminal. But I can't pass a command to the terminal. The second and third still won't work. So none of these achieve what I want. shell "bash -c 'sh " & sFileName & "'" shell "bash -c '" & sFileName & "'" i = shell ("/usr/bin/x-terminal-emulator "&sFileName, 1, , TRUE)' i = shell ("/usr/bin/x-terminal-emulator ", 1, sFileName, TRUE)' (sFileName is the full URL of my bash file)

Pansmanser gravatar imagePansmanser ( 2017-02-07 23:26:12 +0200 )edit

Ok, just ran a test with variable.

    x = Shell ("bash -c 'sh " & sFileName & "'")
    MsgBox x

Correction - this also worked for me:

   Shell "bash -c 'sh " & sFileName & "'"

Just copied you statement (the one immediately above) and pasted into my Sub and it worked fine.

Have used this to run ping on Xubuntu but not on Mint 18. May need modifications:

Shell ("exo-open --launch TerminalEmulator ping -c 5 " & ipAddr & "")

It opened a terminal & ran ping.

Ratslinger gravatar imageRatslinger ( 2017-02-07 23:46:39 +0200 )edit

Switched over to Ubuntu v16.04 (really, really, really don't like) and my sh line wasn't working. Some manipulations and this finally worked:

     x = Shell ("bash",1,sFileName,True)
     MsgBox x

Also, switch xed out for gedit for the text editing statement.

Ratslinger gravatar imageRatslinger ( 2017-02-08 01:37:09 +0200 )edit

Another note on the subject. If the URL is wrong in any way, the return code is still zero. This may be a possible problem on your end from the beginning. Just a guess since I can't figure anything else. My working statement is identical to one of your originals. I found the URL thing because of switching systems and forgot to change it.

Ratslinger gravatar imageRatslinger ( 2017-02-08 02:52:03 +0200 )edit

Aargh! Gotcha. My bash file called a gnuplot control file without specifying the url. Running the terminal in the local directory it worked fine. Calling the shell from basic it did not. 'A possible problem from the beginning.' Yes, but not that url. thanks for your trouble and sorry it was a wild goose chase. (I have also discovered notice that the terminal doesn't find a bash script referred to by its full url (beginning file:///), but wants it to start /home.)

Pansmanser gravatar imagePansmanser ( 2017-02-09 15:29:30 +0200 )edit

Glad you found your problem. Some education for myself so not a lost cause. Still only Xubuntu so far can send & execute commands directly to Terminal with exo-open. Trying to solve that one for my own knowledge to be usable in other environments.

Ratslinger gravatar imageRatslinger ( 2017-02-09 15:46:36 +0200 )edit

Question Tools

1 follower


Asked: 2017-02-06 21:28:51 +0200

Seen: 8,509 times

Last updated: Feb 09 '17