2

I am calling a batch file via c# using powershell library, I see the below error

'jss' is not recognized as an internal or external command,

Whereas manually executing the batch file runs with no issues.

c#

 using (PowerShell powershell = PowerShell.Create())
        {
            powershell.AddCommand("c:\\test.bat", true);
            Collection<PSObject> results = powershell.Invoke();
            PSDataCollection<ErrorRecord> error = powershell.Streams.Error;
            if (error.Count > 0)
            {
                for (int i = 0; i < error.Count; i++)
                {

                }

            }
        }

Batch file

cd C:\Projects\FirstJss

jss deploy app --includeContent --includeDictionary --acceptCertificate

Error

'jss' is not recognized as an internal or external command, enter image description here

1

JSS command line is an part of @sitecore-jss/sitecore-jss-cli npm package. It means that rules on how to run it are exactly the same as for other npm packages.

You need either:

  • Install @sitecore-jss/sitecore-jss-cli globally by execution npm i @sitecore-jss/sitecore-jss-cli -g

or:

  • Installed @sitecore-jss/sitecore-jss-cli to the directory, where you run your script. Change dir to C:\Projects\FirstJss and install it there npm i @sitecore-jss/sitecore-jss-cli
5
  • Thanks @Anton, I applied the fix both globally and locally, It works fine when I click the bat file manually or run those commands via cmd prompt, but while executing it via code its throwing the same exception "jss is not recognized as an internal or external command"
    – sns
    Aug 8 at 12:50
  • @sns Are you able to run jss deploy app --includeContent --includeDictionary --acceptCertificate from Powershell?
    – Anton
    Aug 8 at 13:04
  • Anton , I can run it with Powershell with no issues.
    – sns
    Aug 8 at 13:25
  • Powershell script works fine if I trigger it manually, but when I run it through code it is throwing the same error “Jss is not recognized”
    – sns
    Aug 8 at 15:10
  • @sns it could mean that you call Powershell using not the same user that you use for C# code execution. You can 1) either run your code by the same user or 2) you can install JSS CLI locally in a folder, where you are executing your code or 3) you can install JSS CLI for user that you use for C# code execution.
    – Anton
    Aug 9 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.