1

I am pretty new to coding and am having this issue, can't understand how to fix it, I have seen similar questions asked but, I just cant understand the majority of them. I've tried adding the path several times, have even reinstalled Vscode it just doesn't seem to resolve.

The code I've Written::

import 'dart:io';

void main() {
  print("Enter your name");
  var name = stdin.readLineSync();
  print("The name is $name");
}

The Error I am Getting is:


Jack : The term 'Jack' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, 
or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Jack
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (Jack:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I have tried:

1:Setting the Paths again

2:Reinstall vs code.

Any kind of information will really help, I can't really progress anymore because of this.

nagendra nag
  • 1,142
  • 2
  • 15
Waqas
  • 11
  • 1
  • 1
  • 3

1 Answers1

0

How are you running your program? When I write a program with your exact code, it works.

You have written a command line script in Dart and thus need to run it as such. For example, if you saved your program in the file my_app.dart, then from the command line you could run dart my_app.dart and it'll run your script.

Another way to run it is to create a dart console app and run it using dart run as outlined here: https://dart.dev/tutorials/server/get-started. This would be my recommendation and if you follow the guide I think you'll be able to figure it out, but to quickly confirm your code works you can do the first suggestion.

Andrew
  • 155
  • 1
  • 9
  • The first way is how i do it , it still isn't working , ill look into the other way you have mentioned. – Waqas Mar 02 '22 at 10:08
  • Are you running it directly from the terminal in vs code? Ia it bash? – Andrew Mar 02 '22 at 13:40
  • well i , run the code and enter the name in the terminal. – Waqas Mar 02 '22 at 13:48
  • directly in Vscode. i think. – Waqas Mar 02 '22 at 13:48
  • Your error looks an awful lot like PowerShell, and not bash, which might be the problem – Andrew Mar 02 '22 at 13:59
  • i got another bud who told me its a terminal error , i don't really understand what it actually means because i am new to all this , how do you think this can be fixed ? – Waqas Mar 02 '22 at 14:04
  • Your code works and runs as expected on my machine. I have to assume that you're actually hitting an issue with PowerShell, but I don't know enough about PowerShell to give you advice. If you're open to it, I would suggest running it in a bash terminal. I run bash out of vscode, so you should be able to switch your terminal from PowerShell to bash – Andrew Mar 02 '22 at 20:13