command prompt appears than immediately disappears - python-2.7

I encountered this problem after following a python tutorial on Youtube about creating text files. The instructor had us type in the following code to start:
def createFile(dest):
print dest
if__name__ == '__main__':
createFile('ham')
raw_input('done!')
We had created a folder on the desktop to store the file 'ham' in. But when I double clicked on 'ham' the command prompt window popped on then in a flash it popped off. I am an obvious beginner and I don't know what is going on. Can anyone explain this to me?

You can open command prompt then navigate to python interpreter
directory and run your program by typing python /diretory/to/your/program.py for
example if you have a program named test.py in the directory c:/python and you want to
run it and you have python interpreter installed in C:/python2.x/ directory
then you should open command prompt and type in
cd c:\python2.x\
then you should type
python c:/python/test.py
and perfectly it will work
showing you your program output .

Related

VSCode Extension Run Code can't run C++ in terminal

I am new in C++. I like VSCode very much. I want to run my C++ code in VSCode and so I am using MinGW and Run Code Extension of VSCode.
MinGW setup worked and I could also run my C++ code in the output terminal in VSCode, but when I enabled Code Runner in the settings to run my code in the terminal (so that I can take inputs), I am getting this error:
bash: cd: d:\CodeForces" && g++ inSearchOfAnEasyProblem.cpp -o inSearchOfAnEasyProblem && d:CodeForces"inSearchOfAnEasyProblem: No such file or directory
My Folder structure is: d://CodeForces//inSearchOfAnEasyProblem.cpp
I am trying to run this file: inSearchOfAnEasyProblem.cpp
I am using the Bash terminal. I tried to change the terminal to cmd, but when I click the run button of code runner, it always runs in a bash terminal.
enter image description here
Can anyone please help me? I would have been grateful.

How to call the python program in update mode using pre-buid program?

I have been following the "Making an Emotion-Aware Music Player" tutorial and everything was works fine until running the main program in update.
I searched for "argparse " in tutorials and found nothing about this method.
I have a very little knowledge about python so that could anyone please explain me how run the main program in update mode and where should type the following code.
source page: Making an Emotion-Aware Music Player
Once the file is downloaded, call the main program in “update mode” like this:
~
#To activate update mode, pass the --update flag
python <filename.py> --update
#To get help, use the -h or --help flag
python <filename.py> -h
python <filename.py> --help
When I ran the above code in Command prompt it gave me a error, which says there is no XML file. But as for the main program it should create XML if there wasn't.
I'm using Visual studio 2015 with python 2.7

QProcess can launch programs but not python (command line)

The following code is failing to launch the python command line.
QProcess *myProcess = new QProcess(this);
myProcess->start("\"C:\\Program Files\\Python27\\python.exe\"");
If I replace python27 with (for example)
myProcess->start("\"C:\\Program Files\\Notepad++\\notepad++.exe\"")
notepad opens. Why is my program able to launch notepad but not Python Command Line?
I tried using startDetached() as suggested here but that didn't make a difference.
QProcess::Error() gives me error 5: unknown error.
If you just want to use the 'python console' you must use cmd.exe application from windows
You must have python in PATH so the windows console will know where to take it from.
So, you can try: QProcess::startDetached("cmd", "python")..see more specific syntax details here
It seems I've misunderstood what happens when you launch a command line. I was expecting the python command line or command prompt window to open.
It turns out that if I just pass my commands as arguments start() like so:
myProcess->start("cmd.exe /C python C:\\Users\\SP4\\Desktop\\helloworld.py");
Command prompt runs my python script and I get the output ("Hello World") using:
QString output = myProcess->readAllStandardOutput();
All this happens in the background and you can't actually see a command line window open and print out "Hello, World".
Please correct me if I've misunderstood something.

C++ executable, sh 1:not found

I created a c++ programm that works with ros. The first step would be to open a roscore in a terminal and move on from there. I do so with system("roscore &");
I compiled my file and can run it just fine with ./file.
However, I want to be able to run it as an application (double click). I created a .desktop file and the program shows up in my application list. When i start it though, all I get is a terminal that opens with the message
sh: 1: roscore: not found
etc.
The same applies for the roslaunch commands. I also fork and exec a roslaunch command, which does not work as well.
I tried system("ls"); which worked. All cout messages work as well.
Any idea what is wrong here?
roscore executable is not located in std paths (/bin:/usr/bin:). Use the absolute path - system("/path/to/roscore &")

Try to execute command line codes from c++ linux

I tried the following code, to communicate with the command line from c++ code.
#include<iostream>
#include<cv.h>
int main()
{
system("gnome-terminal");
system("cd");
}
The gnome-terminal command is executing fine. After I close the terminal, when am expecting the cd to execute, however, is not happening. Could you please help me and point out the reason? Thanks. I was expecting the function to make the cmd go down to the home directory
, but it did not. am working in linux
I tried it even by removing gnome. simple cd is not working. am I doing something rong>?
If I try ls, it seems to be working fine!
My main aim is to open a new terminal, and execute commands on that new terminal through the present program that opened the new terminal. Could you please tell me how I can achieve this??
If you want to run a program and wait for it to finish before executing next line, take a look at this page and example code here: http://www.thegeekstuff.com/2012/03/c-process-control-functions/
But if you want to run gnome-terminal and execute a command in newly created window, do this:
system("gnome-terminal -x sh -c 'cd /tmp ; ls -la'");
The system function creates a shell child process to execute the specified command.
cd is a shell command which changes the current working directory of that shell process only.
So the child's cd probably works fine, but it has no effect on your C++ program, which is a different process.
Instead, you probably want to look at the Linux system call chdir.
Thanks for your help!! This command worked perfectly fine from this link
https://superuser.com/questions/198015/open-gnome-terminal-programmatically-and-execute-commands-after-bashrc-was-execu
gnome-terminal -x sh -c 'command1; command2; exec bash'
and I entered the respective commands in the new window. But to change the working directory in the shell am working o, I haven't still figured that out.