Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

powershell script through _shell command

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
davidkoh007
1933 Views, 2 Replies

powershell script through _shell command

Hi

 

I'm trying to run a simple powershell command through (command "_shell" ...) to change .txt file encoding

 

 

 

(setq dwgx (getvar 'dwgprefix))
(setq geox (getfiled "TRW Geocoding file" dwgx "txt" 0))
(setq geox-utf8 (vl-string-subst "-utf8.txt" ".txt" geox))
(setq str (strcat "Powershell.exe Get-Content -Path " geox " | Out-File -FilePath " geox-utf8 " -Encoding ascii"))
(command "_shell" str)

 

 

 

When I pass the string to the _shell command, it just returns nil, and the file is never created.

However when I enter it inside a standalone powershell window (Get-Content -Path [path] | Out-File -FilePath [utf8 path] -Encoding ascii) a new .txt file with the proper encoding is created. (Works even without quotes, the path doesn't contain spaces).

 

Any hints?

2 REPLIES 2
Message 2 of 3
davidkoh007
in reply to: davidkoh007

Figured a workaround

 

(setq ws (vlax-get-or-create-object "WScript.Shell"))
(vlax-invoke ws 'exec str)

Worked. 

Message 3 of 3
dlanorh
in reply to: davidkoh007

It may have something to do with how AutoCAD processes path strings i.e. the escape and path seperator are the same "\" so for a path you must "\\"

I am not one of the robots you're looking for

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report