Using shell command on Windows

I see several posts and documentation on using the shell command. I know it doesn’t work the best with Windows and to write output to a file to then read that file as needed. What I also see in examples using abd in the command. Can you not just do a simple command such as the below to just out the dir contents to somefile.txt? Or what I am missing. Just trying to break it down to really base level I guess

set runThis to "dir > C:\Code\someFile.txt"
shell "c:\Windows\system32\cmd.exe", runThis
log file "C:\Code\someFile.txt"


update your first line to the following and it will work.

set runThis to <</c && dir > "C:\Code\someFile.txt">>

Hope this helps.


Hmm still not getting anything. I even manually created the somefile.txt (with nothing in it) to see if that would help. Manually opening a command prompt and running dir > C:\Code\someFile.txt is working as trying to eliminate maybe some permissions issue.

I believe the /c is to terminate cmd after executing


the wait 2 is to ensure the file is created before reading it. You can also create an if statement that checks if the file exists.
Code for cmd. Removed the && from runthis. its not required and I think the reason why its not putting anything into the file.

set runThis to <</c dir > "C:\temp\someFile222.txt">>
shell "c:\Windows\system32\cmd.exe", runThis
wait 2 
log file "C:\temp\someFile222.txt"

Code for Powershell:

shell "c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe", <<Get-Process | Out-File -FilePath "C:\temp\someFile6.txt" -encoding ASCII>>
wait 2
put file "C:\temp\someFile6.txt"

both are working on my Windows 10 machine.

Woo hoo. Thanks for the help. Like normal, always something simple I am missing, but all is working as I expect now

1 Like