How to run bash script from macro shell? - bash

How can I create a macro (for instance LibreOffice calc) that runs a bash script in terminal (for instance xfce4-terminal). An example:
#!/bin/bash
echo "Hello world"
echo "Press any key to close this window"
read
I tried the Shell command in macro editor, but nothing happened. Here is what I did:
Sub testMysql
Shell ("/mnt/save/janos/home/testbashsql",4)
end Sub
It compiles and runs without error, but no output. As a side question: what does "compile" mean in this context, i.e. what happens to the compiled code? where is it stored? Why is there a "compile" button?
Thanks for helping me better understand macros.

Calling the script will execute the script in a shell. To see results, the script should write to a file rather than stdout, because LibreOffice does not display stdout.
To open a terminal instead, call the terminal. This worked on my system.
Shell("xterm")
Regarding the compile button in the LO IDE, I use it to check Basic code for any syntax errors. I am not aware of any compiled stored code. Documentation is at https://help.libreoffice.org/Basic/Compile.

Related

execute powershell commands with Lua

I have a program that I work with, that has an onboard lua compiler to allow for custom written actions.
Since the tool itself is very limited, especially if it goes for complex reactions over networks, I want to use Powershell over lua.
Methods like os.execute() or io.popen() use the standard command line from windows and not Powershell.
Is there a way to use Powershell with lua?
I tried to write a command line script with the Powershell editor and run this script with os.execute, but it opens it as a textfile, it would be better to write the commands directly in lua but if there is no other way, executing a Powershell script directly would also be fine. (In Windows itself you can execute the script with right mouse "click/Execute with Powershell")
-- You can generate PowerShell script at run-time
local script = [[
Write-Host "Hello, World!"
]]
-- Now create powershell process and feed your script to its stdin
local pipe = io.popen("powershell -command -", "w")
pipe:write(script)
pipe:close()
Your description of the problem makes it sound like you're using a command such as os.execute("powershellscript.ps1"), and that call invokes cmd.exe with your string as the proposed command line. Normally, Windows will open a .PS1 file for editing; this was a deliberate decision for safety. Instead, try altering the os.execute() command to explicitly call PS: os.execute("powershell.exe -file powershellscript.ps1"). If you need to pass parameters to your script, enclose them in {}. See https://msdn.microsoft.com/en-us/powershell/scripting/core-powershell/console/powershell.exe-command-line-help for more info on invoking PowerShell from the command line.

windows command not responding to ruby - trying to call a macro with a .mac file extension

I have a macro file that i can run in the cmd line in windows by simply navigating to the directory and typing profit.mac in the cmd line
however, when i go to call it in a ruby script i keep getting errors
I have tried system(), exec(), ``, and %x() and i havent been able to get it to work
are there any other options I have to call my macro file?
i get the same error on 3/4 of them
(backticks), profit.mac = (Errno::ENOEXEC)
exec('profit.mac') = (Errno::ENOEXEC)
%x('profit.mac') = (Errno::ENOEXEC)
system('profit.mac') = nothing happens
Are your .mac macros files executables or need to be interpreted by another program?
I guess those macros files have to be interpreted by another "macros executor" program. You would need to prepend that in your command execution.
exec('macrosInterpreter.exe /path/to/profit.mac')
It is like running a ruby script. Assume you want to run a test.rb file. You can't do exec('test.rb'), you would have to do exec('ruby test.rb').

Getting continuous output from shell script that is run by Applescript in Cocoa

I have a shell script that is using echo to give a continuous output (the progress of an rsync) that I am using AppleScript to run with administrator privileges. Before I was using NSTask to run the shell script, but I couldn't find a way to run it with the privileges that it needed, so now I am using applescript to run it. When it was running via NSTask, I could use an output pipe and waitForDataInbackgroundAndNotify to get the continuous output and put it into a text field, but now that I am using AppleScript, I cannot seem to find a way to accomplish this. The shell script is still using echo, but it seems to get lost in the AppleScript "wrapper." How do I make sure that the AppleScript sees the output from the shell script and passes it on to the application? Remember, this isn't one single output, but continuous output.
Zero is correct. When you use do shell script, you can consider it similar to using backticks in perl. The command will be executed, and the everything sent to STDOUT will be returned as the result.
The only work around would be to have the your command write the output to a temporary file and then use do shell script "foo" without waiting. From there, you can read from the file sequentially using native AppleScript commands. It's clunky, but it'll work in a pinch.

How to link shared library in shell script?

I have wrote a simple shell script where I have only mentioned the following line
export LD_LIBRARY_PATH=/home/lib/
I want to run one program for which I have to link with this library ,before running the program I am running this shell script ,but after this the program is not working it showing the linking error and when I am doing following line it showing nothing
echo $LD_LIBRARY_PATH
but,when I am doing it in shell normally ,it is working.
Can any one tell why this shell script is not working.what is the concept behind it.
Thanks
If you want to run a script for the purpose of modifying environment variables you need to source the script rather than run the script. Running the script starts a new instance of w/e shell is used to run the script, when it returns, all environment variables are back to the way they were before you ran it. Doing "source script.sh" actually runs the commands in the script in your current shell.

Open Vim from a Rakefile?

I am creating a journal application for personal notes and have the following in my Rakefile:
task :new do
entry_name = "Entries/#{Time.now.to_s.gsub(/[-\ :]+/, '.').gsub(/.0500+/,'')}.md"
`touch #{entry_name}`
`echo "# $(date)" >> #{entry_name}`
end
The last part I would like to include is the opening of the Vim text editor but I am unable to figure out how to open it as if I called it directly from the bash terminal.
I have tried:
vim #{entry_name}
but unfortunately I think both of those open it as a background process.
I have been referencing "6 Ways to Run Shell Commands in Ruby".
As in the article you referenced, `s run the command in a subshell within the current process, but the real problem is that it's trying to take the output from the command run as well, which doesn't play nice with Vim.
You can either:
Use exec to replace the current process with the new one (note that the Ruby/Rake process will end once you've called exec, and nothing after it will run).
Use system to create a subshell like `s, but avoids the problem of trying to grab Vim's stdout. Unlike exec, after Vim terminates, Ruby will continue.
you need to pass the tty as standard input for backspaces etc. to work well in vim:
exec("</dev/tty vim a b")
obviously the backtick (`) didn't work but I was having issues with system/exec from a script.
first I get Vim: Warning: Input is not from a terminal, and then I see ^? when I use backspace.

Resources