PDA

View Full Version : How do I use STARTAPP when I need a full path


madcadder
2005-05-31, 06:43 PM
How do I use STARTAPP when i need a full path...
I want to start Excel for a lisp and need to get to:
C:\Program Files\Microsoft Office\Office\Excel.exe

I tried:
(startapp "C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\EXCEL.EXE" filename)

(startapp ""C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\EXCEL.EXE"" filename)
and neither worked.

Opie
2005-05-31, 07:04 PM
(startapp "C:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\EXCEL.EXE" filename)
switch your "\" to "/" or use a double "\\"; then place a beginning and ending quote within your filename string if it contains spaces in the directory and/or file names.
(setq program "C:\\PROGRAM FILES\\MICROSOFT OFFICE\\OFFICE\\EXCEL.EXE"
filename (strcat "\"c:\\directory with space\\filename with spaces.xls\""))
(startapp program filename)

jwanstaett
2005-05-31, 07:09 PM
(startapp ""C:PROGRAM FILESMICROSOFT OFFICEOFFICEEXCEL.EXE"" filename)

note: from acad help on startapp

If an argument has embedded spaces, it must be surrounded by literal double quotes. For example, to edit the file my stuff.txt with Notepad, use the following syntax:
Command: (startapp "notepad.exe" ""my stuff.txt"")

in lisp string = to and " = to "

kennet.sjoberg
2005-05-31, 07:52 PM
This is real fuzzy, You do not need the double "" for the application, but for the argument, the filname

Important check the "\42 in the beginning and \42" in the end of the argument, the filename
for the argument, the file name :

(setq MyFile "\42C:/Documents and Settings/Kennet/Mina dokument/Firewall.xls\42" )
or
(setq MyFile "\42C:\\Documents and Settings\\Kennet\\Mina dokument\\Firewall.xls\42" )


and for the application + argument :

(startapp "C:\\Program\\Microsoft Office\\Office10\\EXCEL.EXE" MyFile )
or
(startapp "C:/Program/Microsoft Office/Office10/EXCEL.EXE" MyFile )

: ) Happy Computing !

kennet

madcadder
2005-05-31, 08:00 PM
switch your "\" to "/" or use a double "\\"; then place a beginning and ending quote within your filename string if it contains spaces in the directory and/or file names.
(setq program "C:\\PROGRAM FILES\\MICROSOFT OFFICE\\OFFICE\\EXCEL.EXE"
filename (strcat "\"c:\\directory with space\\filename with spaces.xls\""))
(startapp program filename)
closer... now EXCEL starts correctly, but my file path is bad.
FILENAME is defined earlier and
!filename returns:
"G:\\DRAWINGS\\120\\BID PACK PLANS\\120-KEY.xls" (single quotes at ends)
which errors EXCEL into thinking it opening: G:\\DRAWINGS\\120\BID

How can I fix this?

Opie
2005-05-31, 08:14 PM
closer... now EXCEL starts correctly, but my file path is bad.
FILENAME is defined earlier and
!filename returns:
"G:\\DRAWINGS\\120\\BID PACK PLANS\\120-KEY.xls" (single quotes at ends)
which errors EXCEL into thinking it opening: G:\\DRAWINGS\\120\BID

How can I fix this?
Do you have a "/" prior to each quote in your filename variable?

madcadder
2005-05-31, 08:34 PM
No... and starting to feel like Monday. I've done this before with little trouble.
Maybe it's the holiday causing the brainfart.

I'm defining my XLS file here:

(PROGN
(SETQ filename (GETSTRING "File name: "))
(IF (/= (SUBSTR filename (- (STRLEN filename) 3) 4) ".XLS")
(SETQ filename (STRCAT filename ".XLS"))
)
)


to pass to here:

(PROGN
(SETQ program "C:\\PROGRAM FILES\\MICROSOFT OFFICE\\OFFICE\\EXCEL.EXE")
(STARTAPP program filename)
)

Opie
2005-05-31, 09:55 PM
No... and starting to feel like Monday. I've done this before with little trouble.
Maybe it's the holiday causing the brainfart.

I'm defining my XLS file here:

(PROGN
(SETQ filename (GETSTRING "File name: "))
(IF (/= (SUBSTR filename (- (STRLEN filename) 3) 4) ".XLS")
(SETQ filename (STRCAT filename ".XLS"))
)
)


to pass to here:

(PROGN
(SETQ program "C:\\PROGRAM FILES\\MICROSOFT OFFICE\\OFFICE\\EXCEL.EXE")
(STARTAPP program filename)
)

You need to be able to add the quotes into your filename string. This allows excel to open the file (basically like from a DOS command line) even if the filename / directory names contain spaces. If a filename / directory name contain spaces, the program (excel) looks at each segment of the name using the spaces as a delimiter between filenames.

Try this. From your windows run command (located in your windows start menu) type the following (if this file exists, based on your previous posts).
excel "G:\DRAWINGS\120\BID PACK PLANS\120-KEY.xls"
Then press OK.

The above example without the quotes would tell excel to open
g:\DRAWINGS\120\BID.xls
pack.xls
plans\120-key.xls

Sorry, I am starting to ramble, but I think you get the picture.

kennet.sjoberg
2005-05-31, 10:01 PM
Please read my post previous in this thread, it will solve Your problem !

: ) Happy Computing !

kennet

madcadder
2005-05-31, 10:16 PM
Please read my post previous in this thread, it will solve Your problem !

: ) Happy Computing !

kennet
I tried various examples and nothing seems to be working, in any direction

Here it is... I can't fix this last little part.

Opie
2005-05-31, 10:29 PM
I tried various examples and nothing seems to be working, in any direction

Here it is... I can't fix this last little part.
add the beginning and ending quotes to the filename string as such
(STARTAPP program (strcat (chr 34) fname (chr 34)))

madcadder
2005-05-31, 10:42 PM
add the beginning and ending quotes to the filename string as such
(STARTAPP program (strcat (chr 34) fname (chr 34)))
IT WORKED!!!

Is
(chr 34)
the only way to do that?

I tried adding quotes every other way i could think of and they all bombed.

Opie
2005-05-31, 10:47 PM
I don't think it is the only way. I think you could use \" as well. I didn't try it out.

kennet.sjoberg
2005-05-31, 11:08 PM
I don't think it is the only way. I think you could use \" as well. I didn't try it out.

You may try first Richard, please.
"" is hard in lisp

: ) Happy Computing !

kennet

Opie
2005-05-31, 11:10 PM
"" is hard in lisp
You are right kennet, quotes placed in strings is hard in lisp. That is why I was going with placing the quote in the string via its ascii code. Doing this resolved todw's problem.

kennet.sjoberg
2005-05-31, 11:12 PM
Doing this resolved todw's problem.

and as I mentioned very early in this thread this code also do it
(setq fname (strcat "\42" fname "\42" ))

: ) Happy Computing !

kennet

madcadder
2005-05-31, 11:15 PM
I don't think it is the only way. I think you could use " as well. I didn't try it out.This
(STARTAPP program (STRCAT """ fname """))
does not work. I think that's what knocked me off.

when I rinted both:
(STARTAPP program (STRCAT """ fname """))
and
(STARTAPP program (STRCAT (CHR 34) fname (CHR 34)))
they return the same thing as seen from my command lines:

Command: (STRCAT (CHR 34) fname (CHR 34))
""G:DRAWINGSPBID PACK PLANSP-KEY.xls""
Command:
Command: (STRCAT """ fname """)
""G:DRAWINGSPBID PACK PLANSP-KEY.xls""
The second example bombed only showing on the screen:

Command: layer2xls
Name Status Frozen Locked Color LType LWeight Plot
Error: bad argument type: FILE nil
Command:Either way. THANKS! It now works.

Opie
2005-05-31, 11:16 PM
and as I mentioned very early in this thread this code also do it
(setq fname (strcat "\42" fname "\42" ))

: ) Happy Computing !

kennet
kennet,
I don't disagree with your solution, however, your solution either was not tried by todw or it did not resolve his problem.

I was just trying to resolve his problem just like you.

madcadder
2005-05-31, 11:25 PM
Sorry Kennet, I wasn't ignoring you.

I did try the /42 option and it didn't work either which is why I did not comment.
I tried it as
(STARTAPP program (STRCAT "\42fname\42")) and
(STARTAPP program (STRCAT "\42" fname "\42"))

it gave the same error and info as when the other bombed
Command: layer2xls
Name Status Frozen Locked Color LType LWeight Plot
Error: bad argument type: FILE nil
Command:

kennet.sjoberg
2005-05-31, 11:27 PM
And here is changes for the layer2xls.lsp file


(IF (= ask "Yes")
(PROGN
(SETQ program "C:\\PROGRAM FILES\\MICROSOFT OFFICE\\OFFICE\\EXCEL.EXE" )
(setq fname (strcat "\42" fname "\42" ))
(STARTAPP program fname)
)
)



: ) Happy Computing !

kennet

madcadder
2005-05-31, 11:47 PM
And here is changes for the layer2xls.lsp file


(IF (= ask "Yes")
(PROGN
(SETQ program "C:\\PROGRAM FILES\\MICROSOFT OFFICE\\OFFICE\\EXCEL.EXE" )
(setq fname (strcat "\42" fname "\42" ))
(STARTAPP program fname)
)
)



: ) Happy Computing !

kennet
It bombed...

Command: layer2xls
Name Status Frozen Locked Color LType LWeight Plot
Error: bad argument type: FILE nil

Everything but the (chr 34) version bombed. I don't know why. they all tested out to show she same info, but only one actually opened Excel to the file on the network.


Thanks for all of everyones help. I'm just going to leave it at the (chr 34) version and call it good.
(for now)

madcadder
2005-05-31, 11:50 PM
here is the share of the working copy.

kennet.sjoberg
2005-06-01, 12:49 AM
It bombed...
Strange, it works for me in AutoCAD 2002 on
Windows XP home and on Windows XP professional
but I am not saving to a network drive.
Tomorrow (yes I have past midnight right now ) I am going to test
in AutoCAD 2006 / ADT on Windows XP and on a network drive.

I can see that we have a difference in the Excel path
What kind of operating system do You have ?
and
Which AutoCAD version do You have ?

I can not simulate the :
"Command: layer2xls"
"Name Status Frozen Locked Color LType LWeight Plot"
"Error: bad argument type: FILE nil"
not even with a faked filename.

: ) Happy Computing !

kennet

kennet.sjoberg
2005-06-01, 09:18 AM
Yes the code works also in

AutoCAD 2002 on XP
AutoCAD 2006 on XP
ADT 2006 on XP

to a network drive into a folder with space in the name

(IF (= ask "Yes")
(PROGN
(SETQ program "C:\\PROGRAM FILES\\MICROSOFT OFFICE\\OFFICE\\EXCEL.EXE" )
(setq fname (strcat "\42" fname "\42" ))
(STARTAPP program fname)
)
)



: ) Happy Computing !

madcadder
2005-06-01, 03:13 PM
Strange, it works for me in AutoCAD 2002 on
Windows XP home and on Windows XP professional
but I am not saving to a network drive.
Tomorrow (yes I have past midnight right now ) I am going to test
in AutoCAD 2006 / ADT on Windows XP and on a network drive.

I can see that we have a difference in the Excel path
What kind of operating system do You have ?
and
Which AutoCAD version do You have ?

I can not simulate the :
"Command: layer2xls"
"Name Status Frozen Locked Color LType LWeight Plot"
"Error: bad argument type: FILE nil"
not even with a faked filename.

: ) Happy Computing !

kennet
Thank you very much for the Above and Beyond. It was just wierd that testing would look the same, but actually running program would yield different outcomes.

I'm also AutoCAD 2002 on WinXP Pro.
At the time I was testing: C-local drive, D-CD(empty),E-Flashdrive,F-Network,G-Network (location of file on G:\)
Drive G is pathed to Windows, but not pathed to CAD in any way other than current working file.
All lisp are local.

Opie
2005-06-01, 03:45 PM
Yes the code works also in

AutoCAD 2002 on XP
AutoCAD 2006 on XP
ADT 2006 on XP

to a network drive into a folder with space in the name

(IF (= ask "Yes")
(PROGN
(SETQ program "C:\\PROGRAM FILES\\MICROSOFT OFFICE\\OFFICE\\EXCEL.EXE" )
(setq fname (strcat "\42" fname "\42" ))
(STARTAPP program fname)
)
)



: ) Happy Computing !
kennet,

Is using the octal codes just as comparable to using the ascii codes?

madcadder
2005-06-01, 04:29 PM
After a morning of testing with different results than yesterday:


(IF (= ask "Yes")
(PROGN (SETQ program "C:\\PROGRAM FILES\\MICROSOFT OFFICE\\OFFICE\\EXCEL.EXE")
;;; (SETQ fname (STRCAT "\42" fname "\42")) ;this works-opt B
;;; (SETQ fname (STRCAT (CHR 34) fname (CHR 34))) ;this works-opt C
;;; (STARTAPP program fname) ;this works-opt B & C
;;; (STARTAPP program (STRCAT "\42" fname "\42")) ;this works-opt D
(STARTAPP program (STRCAT (CHR 34) fname (CHR 34))) ;this works-opt A
)
)

kennet.sjoberg
2005-06-01, 05:01 PM
. . . . using the octal codes just as comparable to using the ascii codes?
Yes, I have had problem with the ASCII code, but
After a morning of testing with different results than yesterday:
I can see that both methods still works and is usable in the right way ;-)

: ) Happy Computing !

kennet