1

I want to run a python script from the c. i tried it compile successfully but it give error "python is not recognized as internal or external command, operable program or batch file".

 #include <iostream>
 using namespace std;
 // main() is where program execution begins.

 int main()
 {
    std::string filename = "hi.py";
    std::string command = "python ";
    command += filename;


    FILE* in = popen(command.c_str(), "r");
    pclose(in);
    return 0;
 }
Biruntha G
  • 27
  • 2
  • 10
  • Where (what directory) is your C program running from? Try running python with the full path where it is installed. – Vini.g.fer Nov 04 '15 at 16:09
  • Is `python` in the standard program search path? Can you, from a command prompt and in any directory, start Python by writing the command `python`? – Some programmer dude Nov 04 '15 at 16:10
  • @ Joachim Pileborg it is in the standard program search path.when i type it give python version – Biruntha G Nov 04 '15 at 16:16
  • Possible duplicate of [python is not recognized as an internal or external command](http://stackoverflow.com/questions/14433499/python-is-not-recognized-as-an-internal-or-external-command) – Sadık Nov 04 '15 at 18:12

1 Answers1

0

You want to use the full path to your python executable, something like:

std::string command = "/usr/bin/python ";
Paul Evans
  • 27,315
  • 3
  • 37
  • 54