powershell script through _shell command

powershell script through _shell command

davidkoh007
Contributor Contributor
2,334 Views
2 Replies
Message 1 of 3

powershell script through _shell command

davidkoh007
Contributor
Contributor

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?

0 Likes
Accepted solutions (1)
2,335 Views
2 Replies
Replies (2)
Message 2 of 3

davidkoh007
Contributor
Contributor
Accepted solution

Figured a workaround

 

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

Worked. 

Message 3 of 3

dlanorh
Advisor
Advisor
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

0 Likes