Old 06-19-2018, 07:40 AM   #1
atonalist
Human being with feelings
 
Join Date: May 2018
Location: Stony Brook, New York
Posts: 3
Default os.execute in REAPER script under Wine.

I am probably doing something pretty stupid, as I'm pretty new to Lua.

I have a small bash script I'd like to run from a custom REAPER command, (it's for cleaning up a student user directory when they've inevitably sprayed files all over the place, as they are wont to do).

I'm running REAPER under WINE in Linux, and all my other .lua scripts work fine, but when I try to call os.execute("sh ~/MyScript.sh") nothing happens.

I checked the return value on os.execute("sh ~/MyScript.sh") and it's coming back nil, though it returns 'true' if I run other commands, such as os.execute("echo test-value")

When I run direct from the terminal, it works just fine, so I don't think the fault lies in the script itself but how I'm calling it. Also, works just as intended on OsX, so this could be my being dumb about Linux.

Here's a highly-simplified version of the entire script:

--Test Script for os.execute Reaper on WINE
--Command as written runs in terminal, but fails in a REAPER script.

local function Msg(str)
reaper.ShowConsoleMsg(tostring(str).."\n")
end
--quick debug message

Msg(os.execute('sh ~/MkDirMvFiles.sh'))

--Msg(package.config:sub(1,1))
--Gets the path seperator, which tells us whether Lua thinks she's in Windows or Unix. Returns "/" rather than "\" on Wine, so Unix?
atonalist is offline   Reply With Quote
Old 06-19-2018, 09:14 AM   #2
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

- I'd include the shell script anyway just in case
- For better readability on the forum, you can put code inside [ code ] and [/ code ] tags (remove the spaces) or use the # button in the post editor (I think it has to be in advanced mode or something... it gives you buttons for bold, underline, center, bullets, etc)
- Not sure if Linux needs something similar, but for Windows you need to make sure that sh's root folder is part of the system path to be able to call it from anywhere you want as opposed to c:/shellscript/bin/sh
- Regarding the last line of your Lua script, AFAIK all three OSes will play happily with / as a separator, so you shouldn't have to worry about it. Mac and Linux use / I believe, and Windows doesn't even care if I mix the two: c:\users\me\appdata/roaming\REAPER/scripts\lokasenna/testing.lua.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 06-19-2018, 09:26 AM   #3
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Try the following:
Every command in your shell-sript should include the absolute path to the command. See if that works.
With the windows version of os.execute, I've seen the problem occuring, that no environment-variables were set in the "command-line-instance" executed by os.execute. That way, no command could be found that wasn't part of cmd.exe.
Maybe that is the same problem on Linux.

You can also check out:
https://www.reaper.fm/sdk/reascript/...ml#ExecProcess
which is Reaper's own execute-function.

SWS also has one, called reaper.BR_Win32_ShellExecute(). It is only available, when you have SWS installed, though.
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-27-2021, 06:08 AM   #4
BartR
Human being with feelings
 
BartR's Avatar
 
Join Date: Oct 2014
Location: Belgium
Posts: 1,612
Default

Quote:
Originally Posted by mespotine View Post
Try the following:
Every command in your shell-sript should include the absolute path to the command. See if that works.
With the windows version of os.execute, I've seen the problem occuring, that no environment-variables were set in the "command-line-instance" executed by os.execute. That way, no command could be found that wasn't part of cmd.exe.
Maybe that is the same problem on Linux.

You can also check out:
https://www.reaper.fm/sdk/reascript/...ml#ExecProcess
which is Reaper's own execute-function.

SWS also has one, called reaper.BR_Win32_ShellExecute(). It is only available, when you have SWS installed, though.
how to deal with spaces?

Code:
os.execute("start c:/program files/blablabla/bla.exe")
it returns
Code:
Windows cannot fine 'C:/Program'. Make sure you typed the name correctly, and then try again.
[/code]
__________________
Reaper: always the most up-to-date.
O.S.: Windows 11 Pro
ReaPack (with bilingual Tutorials): https://bit.ly/ReaPack_Repository
BartR is offline   Reply With Quote
Old 02-27-2021, 09:00 AM   #5
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Enclose these filenames with

Code:
\"
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-27-2021, 12:01 PM   #6
BartR
Human being with feelings
 
BartR's Avatar
 
Join Date: Oct 2014
Location: Belgium
Posts: 1,612
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
Enclose these filenames with

Code:
\"
I tried. It didn't get it. I had to write progra~2 instead. Old DOS stuff :-)
__________________
Reaper: always the most up-to-date.
O.S.: Windows 11 Pro
ReaPack (with bilingual Tutorials): https://bit.ly/ReaPack_Repository
BartR is offline   Reply With Quote
Old 02-27-2021, 01:12 PM   #7
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,621
Default

Have you tried using backslashes as folder-separator? Even though Lua tries to convert them automatically, I wouldn't trust Lua with that.

Especially as the line in os.execute is interpreted by the command line and not Lua.
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote
Old 02-28-2021, 03:15 AM   #8
solger
Human being with feelings
 
solger's Avatar
 
Join Date: Mar 2013
Posts: 5,844
Default

Quote:
Originally Posted by BartR View Post
how to deal with spaces?

Code:
os.execute("start c:/program files/blablabla/bla.exe")
Here are some examples:

Code:
local path = "c:/program files/blablabla/bla.exe"
os.execute('start "" "' .. path .. '"')
Code:
local path = "c:/program files/blablabla/bla.exe"
reaper.BR_Win32_ShellExecute("open", path, "", "", 1)
Code:
local directory = "c:/program files/blablabla"
local fileName = "bla.exe"
reaper.BR_Win32_ShellExecute("open", fileName, "", directory , 1)
__________________
ReaLauncher
solger is offline   Reply With Quote
Old 02-28-2021, 04:25 AM   #9
BartR
Human being with feelings
 
BartR's Avatar
 
Join Date: Oct 2014
Location: Belgium
Posts: 1,612
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
Have you tried using backslashes as folder-separator? Even though Lua tries to convert them automatically, I wouldn't trust Lua with that.

Especially as the line in os.execute is interpreted by the command line and not Lua.
Yes I did try but it was not working.
For the rest I agree with you about the reliability.
I will try some other stuff again.
__________________
Reaper: always the most up-to-date.
O.S.: Windows 11 Pro
ReaPack (with bilingual Tutorials): https://bit.ly/ReaPack_Repository
BartR is offline   Reply With Quote
Old 02-28-2021, 05:15 AM   #10
BartR
Human being with feelings
 
BartR's Avatar
 
Join Date: Oct 2014
Location: Belgium
Posts: 1,612
Default

Quote:
Originally Posted by solger View Post
Here are some examples:

Code:
local path = "c:/program files/blablabla/bla.exe"
os.execute('start "" "' .. path .. '"')
Code:
local path = "c:/program files/blablabla/bla.exe"
reaper.BR_Win32_ShellExecute("open", path, "", "", 1)
Code:
local directory = "c:/program files/blablabla"
local fileName = "bla.exe"
reaper.BR_Win32_ShellExecute("open", fileName, "", directory , 1)
Thank you so much Solger.
The last 2 solutions worked perfectly
__________________
Reaper: always the most up-to-date.
O.S.: Windows 11 Pro
ReaPack (with bilingual Tutorials): https://bit.ly/ReaPack_Repository
BartR is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:32 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.