I have made a python program which will create an OpenGL and render a teapot (GLUT standard teapot) with a shader that I specify. The shader is specified as follows:

  • I have a file called "index.ini" which contains the file paths to a vertex shader and pixel shader file
  • The program gets the contents of "index.ini" using "sys.argv[1]"
  • I run the program from CMD with the following: "test.py index.ini"

I want to be able to right click on "index.ini" and open it by default with a C++ program, which will get the path to "index.ini" through "argv" and pass it to CMD, where I can make a call such as "test.py index.ini", using "system()". I have tried the following, but the program just hangs and then crashes.

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main(char *argv[])
{
    string toCall="<PATH>\\test.py ";
    string file=argv[1];
    cout<<argv[1]<<endl;
    system("pause");
    string finalCall = toCall + file;
    system(finalCall.c_str());
}

Thanks :)

Your main() does not have the proper signature for taking arguments, you want to have ..

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;

int main(int argc, char *argv[])
{
  ...

You might also want to check that argc is equal to (at least) 2.

commented: Danke schon :D +2

Cheers :D Works great :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.