-
Notifications
You must be signed in to change notification settings - Fork 284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
{command} is not recognized as an internal or external command, operable program or batch file. in PowerShell 7 #95
Comments
Same problem |
Short answer is to call this before ai-shell.
Long answer is: AI-Shell uses execa to execute the generated scripts, and attempts to determine your shell by checking the process.env.SHELL environment variable. On Windows, that's undefined and so it passes "shell:true" which executes cmd.exe. (shell:false also fails so but I didn't dig further).
|
@jakenuts maybe run a PowerShell command to set the env value if it succeeds? // by gpt4
const child_process = require('child_process');
function isRunningInPowershell() {
try {
// Execute a PowerShell-specific command
child_process.execSync('Get-Process -Id $PID', { stdio: 'ignore' });
return true;
} catch (e) {
return false;
}
}
if (isRunningInPowershell()) {
console.log("Running in PowerShell. Setting environment variable.");
// Set the environment variable
process.env.SHELL = "Powershell";
console.log("Environment variable set:", process.env.SHELL);
// Add any other PowerShell-specific operations here
} else {
console.log("Not running in PowerShell, perform standard operations.");
// Add standard operations here
} |
@mefengl Sure, that would likely work. Actually I just found another way suggested by someone on SO. Instead of trying to detect the shell inside the node project, create a ai.cmd and ai.ps1 file and when the user types "ai" each shell will call the one with it's default extension. Turns out, there already is an ai.cmd and ai.ps1 C:\Users{yourname}\AppData\Roaming\npm so you could probably just set the shell variable or pass an argument into the script from there. I bet a clever PowerShell person (definitely not me) could even pass an argument into the ai-shell script to just return the script instead of using execa and (or copy it to the clipboard) then execute that output within the same PowerShell context you started in. |
I do not seem to be able to run commands in PowerShell 7.3.6 in Windows Terminal 1.17.11461.0 on Windows 10 21H2 (19044.3208).
Example:
The text was updated successfully, but these errors were encountered: