Why does shell with attrib does not work?

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Why does shell with attrib does not work?

Post by mrcoollion » Sat Aug 22, 2015 2:48 pm

I get the following error on a simple shell command and I cannot find what I am doing wrong?
I only need to hide this folder.
Using Livecode 7.1.0-rc-1 Build 10040 (indy developer)
Working on Windows 10
Works fine as a commandLine in the Terminal window However I needer to use quotes before and after the folder path.

This worked fine in the commandline window:
D:\>attrib +h "D:\test folder\subfolder"
D:\>attrib -h "D:\test folder\subfolder"
D:\>

The error message: button "Hide folder": execution error at line 2 (Handler: can't find handler) near "shell", char 1

the script:

Code: Select all

on mouseUp
   shell ("attrib +h D:\test folder\subfolder")
   answer the result
end mouseUp
Also tried without succes:

Code: Select all

shell ("attrib +h " & quote & "D:\test folder\subfolder" & quote)
Anyone has a hint or tip?

ClipArtGuy
Posts: 253
Joined: Wed Aug 19, 2015 4:29 pm

Re: Why does shell with attrib does not work?

Post by ClipArtGuy » Sat Aug 22, 2015 4:18 pm

maybe this:

Code: Select all

shell ("attrib +h " & quote & "D:\test"&space&"folder\subfolder" & quote)
I have had trouble using shell command in windows when there are spaces in a path, although I mostly use Linux these days...

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Why does shell with attrib does not work?

Post by mrcoollion » Sat Aug 22, 2015 6:33 pm

Thanks ClipArtGuy for your reaction but no luck. Your suggestion does not work ;-(
It also does not work if I take the dpaces out of the folder name.

Regards,

Paul
Last edited by mrcoollion on Sat Aug 22, 2015 6:50 pm, edited 1 time in total.

zaxos
Posts: 222
Joined: Thu May 23, 2013 11:15 pm

Re: Why does shell with attrib does not work?

Post by zaxos » Sat Aug 22, 2015 6:37 pm

shell is a function, you have to put it or get it :P

Code: Select all

put shell("bla bla bla")
OR
get shell("bla bla bla")
Knowledge is meant to be shared.

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Why does shell with attrib does not work?

Post by mrcoollion » Sat Aug 22, 2015 6:55 pm

Thanks zaxos.
I am almost to embarrassed to say that you were correct.
Now with Put in front the shell command works.

Thanks again for the lesson.

to be complete for others this code shows what does and what does not work!
might be nice if this is also mentioned in the examples for the shell command at http://docs.runrev.com/Function/shell

Code: Select all

on mouseUp
   put 2 into thechoice 
   if thechoice is 1 then put "attrib +h D:\test folder\subfolder" into thecommand // does NOT work giving error: Parameter format not correct -
   if thechoice is 2 then put "attrib +h " & quote & "D:\test folder\subfolder" & quote into thecommand // does work
   if thechoice is 3 then put "attrib +h " & quote & "D:\test"&space&"folder\subfolder" & quote into thecommand // does work
   put shell (thecommand) into tempvar
   if tempvar is not empty then answer "error: " & tempvar
end mouseUp
Kind regards,

Paul

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Why does shell with attrib does not work?

Post by sturgis » Sat Aug 29, 2015 7:22 pm

Theres another thing I do on windows that makes things easier..

put shortfilepath("D:\test folder\subfolder") into tPath

at which point tPath has the old style 8.3 no spaces path to the file.

merge can be pretty helpful too.

If you have this string saved..

"attrib +h [[tPath]]" in a variable named tCommand

you can then
put shell(merge("tCommand"))
and it will replace [[tPath]] with the contents of tPath

So, if I did
put shortfilepath("C:\Program Files (x86)\RunRev\LiveCode Community 8.0 (dp 3)\LiveCode Community.exe") into tPath
the shell command shell(merge(tCommand)) would end up with

"attrib +h C:\PROGRA~2\RunRev\LIVECO~3.0(D\LIVECO~1.EXE" (note the shortfilepath version)

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Why does shell with attrib does not work?

Post by mrcoollion » Sat Aug 29, 2015 7:45 pm

sturgis wrote:Theres another thing I do on windows that makes things easier..

put shortfilepath("D:\test folder\subfolder") into tPath

at which point tPath has the old style 8.3 no spaces path to the file.

merge can be pretty helpful too.

If you have this string saved..

"attrib +h [[tPath]]" in a variable named tCommand

you can then
put shell(merge("tCommand"))
and it will replace [[tPath]] with the contents of tPath

So, if I did
put shortfilepath("C:\Program Files (x86)\RunRev\LiveCode Community 8.0 (dp 3)\LiveCode Community.exe") into tPath
the shell command shell(merge(tCommand)) would end up with

"attrib +h C:\PROGRA~2\RunRev\LIVECO~3.0(D\LIVECO~1.EXE" (note the shortfilepath version)
THX 8)

Post Reply