简体   繁体   中英

Call ps1 from cmd

I want to call ps1 from command line, there are 2 files in same folder (very straight forward)

test.cmd :

@set powershell=powershell.exe
echo ^^^&'%~dpn0.ps1' %*| "%powershell%" -ExecutionPolicy Bypass -Command -
exit /b %ERRORLEVEL%

test.ps1 :

ls>abc.txt

The problem is: When I call test.cmd from command line, abc.txt does't get generated. but When I call test.ps1 from powershell ise from that folder, abc.txt is created. I'm also be able to call powershell.exe from that folder as well.

Did I miss something?

This issue was sorted. I have 's in my folder's name, once I remove it, it's working fine.

Thanks guys!!

Are you sure ls>test.txt worked by just running the test.ps1 script?

You have to write is as ls > test.txt for it to work and I have confirmed that that works from test.cmd as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM