News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
Pages (2): « First [1] 2 Next > Last »
"murgaLua -e string" in Windows and Mac
Author Message
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
"murgaLua -e string" in Windows and Mac

I wonder if someone on Windows and Mac could do a test for me.
The -e option of murgaLua should allow you to run a string that can be applied to a given script.

In Linux I can pass a variable to a script using the following:

Code:
murgaLua -e 'variable=\"this is a string\"' scriptname.lua

This apparently doesn't work in Windows, and I'm not sure about Mac (I think it probably works).

If someone could do a test or two to see if it might work with 'variable=[[this is a string]]' or something similar, could you please post the solution here?

Thanks.

02-22-2008 05:09 AM
Find all posts by this user Quote this message in a reply
iGame3D
Moderator
***


Posts: 231
Group: Moderators
Joined: Apr 2007
Status: Offline
Reputation: 0
Post: #2
RE: "murgaLua -e string" in Windows and Mac

Looks like it works on Mac.

Code:
if a~= nil then
if a==1 then print("ok") end
end


Code:
murgaLua -e 'a=1' /Volumes/iGame3D/test.lua

Returned "ok"

02-22-2008 07:17 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #3
RE: "murgaLua -e string" in Windows and Mac

mikshaw Wrote:
In Linux I can pass a variable to a script using the following:

Code:
murgaLua -e 'variable=\"this is a string\"' scriptname.lua

This apparently doesn't work in Windows, and I'm not sure about Mac (I think it probably works).


Why do you think that this doesn't work in Windows?
You don't have to escape the double quotes when you use the single quotes. lua -e 'variable="string"' works perfectly. You only have to escape the double quotes when you use double quotes to quote ;-) (-e "variable=\"string\"")

On Windows you can only use double quotes, but the escape mechanism is the same as on Linux or nearly every other OS.

Juergen

02-22-2008 08:05 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #4
RE: "murgaLua -e string" in Windows and Mac

Quote:
Why do you think that this doesn't work in Windows?

Because the last time i had access to a windows machine I tested it and it failed.

Quote:
You don't have to escape the double quotes when you use the single quotes. lua -e 'variable="string"' works perfectly.

I wasn't aware of this. Thanks for the lesson.

Quote:
On Windows you can only use double quotes

I'm guessing it was probably the backspace that was causing the error then? Or do I need to always use only double quotes if I want it to work in Windows? If that's the case how would you nest quotes?

02-22-2008 12:06 PM
Find all posts by this user Quote this message in a reply
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #5
RE: "murgaLua -e string" in Windows and Mac

Quote:
On Windows you can only use double quotes

I'm guessing it was probably the backspace that was causing the error then? Or do I need to always use only double quotes if I want it to work in Windows? If that's the case how would you nest quotes?
[/quote]
The same as on Linux:

Code:
lua -e var="string" --doesn' work on Windows or Linux
lua -e var='string' -- does work on Windows but not on Linux
lua -e var=\"string\" --does work on Windows and Linux
lua -e "var=\"string\"" --does work on both
lua -e 'var="string"' -- works on Linux but not on Windows
lua -e "var='string'" -- works on both
lua -e "var=\'string\'" -- works on Linux but not on Windows
lua -e var1=\"string\"\ var2=\"string\" -- works on Linux but not on Windows
...

This applies to Bourne/Korn compatible shells on Linux and CMD on Windows. Other shells might have a different quoting behavior.

Juergen

02-22-2008 08:12 PM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #6
RE: "murgaLua -e string" in Windows and Mac

Ok, if it works on Windows there is something else causing the problem.
Specifically what I'm trying to do is run a separate murgaLua process that runs a new script using a variable created in the current script. This is what I have working in Linux:

Code:
io.popen(MURGALUA.." -e 'images=\""..images.."\"' "..tempfile)

MURGALUA is the murgaLua executable
tempfile is a dynamically created script file
images is a Lua variable being passed, which is a directory that tempfile wouldn't be able to find otherwise.
If I recall correctly, I got a "bad symbol" error in Windows.

This also works in Linux, but I haven't yet tested in Windows:

Code:
io.popen(MURGALUA..[[ -e 'images="]]..images..[["' ]]..tempfile)


Maybe there is a problem with the string being interpreted first for io.popen and then being misinterpreted when it's run. It might end up being sent in this format:

Quote:
lua -e 'var="string"' -- works on Linux but not on Windows

If that's the case, I think it might be a problem with using a backslash escape after all.
It looks like one option could be something like this:

Code:
io.popen(MURGALUA..' -e "images=\"'..images..'\"" '..tempfile)

which I hope would run this command:

Code:
murgaLua -e "images=\"<images path>\"" <new script>

However, I could see it doing this instead:

Code:
murgaLua -e "images="<images path>"" <new script>

which I guess would probably also fail.

Perhaps the best solution would be

Code:
io.popen(MURGALUA..[[ -e "images=']]..images..[['" ]]..tempfile)

which is essentially the same as the second one above but with the single and double quotes swapped, hopefully resulting in this:

Code:
murgaLua -e "images='<images path>'" <new script>

That one looks like it should work in Windows.

02-22-2008 08:55 PM
Find all posts by this user Quote this message in a reply
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #7
RE: "murgaLua -e string" in Windows and Mac

Hi Mike,

first you don't need the outer quotes. lua -e var=\"string\" works. The outer quotes are only necessary if there is a space in the "-e" argument, because then it would be treated as two separate arguments and interpreted as a filename. For example lua -e var1=\"string\" var2=\"string\" would not work. But lua -e var1=\"string\" -e var2=\"string\" or lua -e "var1=\"string\" var2=\"string\"". On Linux there is also the possibility to escape/quote the space charecter ("\ ") so that the Lua interpreter doesn't see two arguments.

There is one logical error in your examples. If you want to the shell to see something like "var=\"string\"" then you have to write it the following way:

Code:
io.popen(MURGALUA.." -e \"images=\\\""..images.."\\\" "..tempfile)

You forgot to escape/quote the backslash so that it could be send literally to the shell. In your examples you quoted only the double quotes (in the Lua string) to appear in the shell. If you also quote the backslash it should work without problems.

Juergen

This post was last modified: 02-22-2008 11:13 PM by Juergen.

02-22-2008 09:55 PM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #8
RE: "murgaLua -e string" in Windows and Mac

Quote:
The outer quotes are only necessary if there is a space in the "-e" argument

That's a strong possibility, though. The script checks the location of itself and uses that directory as the value of images. In windows it is almost guaranteed that there will be a space in there if the user has the script somewhere in his home directory ("C:\Documents and Settings\username\", for example). I've always hated this aspect of Windows, but it's there so I have to deal with it. Perhaps just having quotes around the value of the variable is enough to tell the shell that images="C:\Documents and Settings\username\" is a single parameter? In other words, would this be passed correctly:
murgaLua -e images="C:\Documents and Settings\username\" scriptname
EDIT: no, that doesn't even work in Linux. The entire string after -e must be passed as a single string regardless of whether or not there are spaces. murgaLua -e variable="a_string_without_spaces" didn't even work.

Quote:
You forgot to escape/quote the backslash so that it could be send literally to the shell.

I'd actually thought about this briefly, but it seemed that if it works in Linux then maybe it's not an issue. After seeing your example of the way double quotes nested within single quotes don't work in Windows, I believe you're correct.
Unfortunately escaping escapes is something that has always bothered me as well....mostly just because it looks messy and is sometimes hard for me to follow.

I'm hoping that the double brackets will work instead of needing to escape quotes, mainly because it is the cleaner method in my opinion.

This post was last modified: 02-23-2008 02:30 AM by mikshaw.

02-23-2008 01:10 AM
Find all posts by this user Quote this message in a reply
Juergen
Member
***


Posts: 81
Group: Registered
Joined: May 2007
Status: Offline
Reputation: 0
Post: #9
RE: "murgaLua -e string" in Windows and Mac

If you wan't to set a filename in the script you wan't to call, it might be a little bit harder. Although there might be a few solutions. I think the easiest solution would be to replace the "\" with "/" and replace them in the script you call again (string.gsub(var,"(\\)","/")). There could be also be another problem, because Windows user put all kind of weird characters in their filenames, because they can.

If you want to be really on the save side you can do the following (although it might be a little bit overkill):

Code:
io.popen(MURGALUA.." -e images=\""..(mime.b64(file,nil)).."\" "..scriptname,"r")
--in the script you can get the directory with:
images=(mime.unb64(images,nil))

While this might be a little bit overkill, it is a method that wil definitely work.

Juergen

02-23-2008 03:58 AM
Find all posts by this user Quote this message in a reply
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #10
RE: "murgaLua -e string" in Windows and Mac

I think you might be reading more into this than is necessary. Yes, I understand that there could be weird characters in a Windows path, but that's something I have no interest in supporting. All I'm trying to do here is to pass the lua command images="some path". If that path has ridiculous characters in it and the script fails, I don't care...I see that as a moronic thing that the end user will have to deal with. File paths should be alphanumeric, and anything else beyond spaces (which are sadly much too common to ignore) is not worth my time.

I will look into this last suggestion, though, since it doesn't seem to be too complicated as far as filesize and processing goes.

Thank you for all your help. I'm not sure when I'll next be testing on windows, but you've given me a lot of options that I hadn't seen before.

edit: alphanumeric is probably a bit more restrictive than I intended. There are a few characters, underscores and hyphens (and tilde for backups), that are acceptible. Just about anything else has the potential to cause problems for numerous applications.

This post was last modified: 02-28-2008 12:03 AM by mikshaw.

02-23-2008 11:21 AM
Find all posts by this user Quote this message in a reply
Pages (2): « First [1] 2 Next > Last »
Post Reply  Post Thread 

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: