I am new to Kdevelop and I am trying for 2 hours to run a project based on input parameters in C++ style.
The code is here:
int main(int argc, char** argv)
{
std::string s = args[1]
std::cout<<s<<std::endl;
}
I am trying to add the parameter, but it is crashing and saying
Process Error - Kdevelop
A shell meta character was included in the atguments for file launch ...
Can anyone tell me what is it about? Andhow can I fix it, or where shall I add the execution parameters?
I have placed them in the Launch -> Configuration Launches -> Behaviour -> Arguments see below
Please help
The arguments must be between quotes:
"/your folder and path/Your file"
or
"enter your parameter here"
instead of
just the parameter
Related
I'm trying to use VideoCapture. a part of my code is below.
when I run my code, I got this :
Error! Insufficient parameters provided.
How can I use my video with this code. I want to open a stream with VLC.
Or if is there any other way, I'd like to use.
I searched that argv[1] is will be my video file. But I don't know how to show my file and how to define my file to this code.
To help future users, I'd make some changes:
Was:
LOG_DEBUG("Error! Insufficient parameters provided.");
Is:
std::string program(argv[0]);
LOG_DEBUG("Error! Insufficient parameters provided.");
LOG_DEBUG("Please provide a command line argument.");
LOG_DEBUG("Example: " << program << " VIDEO_FILE_NAME");
Explanation:
On the command line, when the program is invoked, the arguments from the command line are copied in the array of strings held by argv. argv[0] is the first argument and it is the filename of the program itself. Put another way, argv[i] for 0 <= i < argc are populated in the array of strings argv from the command line. If you renamed the program executable file, argv[0] would be different the next time you ran the program.
The array argv is indexed from 0 to argc-1. When main is invoked this array of strings and argc are set. It's up to the software to decide what to do. In this case your application tests argc and finds that if no argument is provided (ie., argc < 2) then the one user argument provided by the user is not present, report the error and return.
Incidentally, there's yet another form of main you can use:
int main(int argc, char** argv, char** envp)
argc = number of arguments.
argv = array of argument strings
envp = array of environment variable name=value pairs
So beyond simple command line argument passing, one could choose to write the main function to grab the environment variables (not shell variables) and decide nuanced action based on that. Options abound.
But for the time being, your code would be helpful if it reported why there is an error and the suggestions provided seem to do that.
Good luck.
This question already exists:
C++ create new windows command [closed]
Closed 4 years ago.
I am trying to create a C++ console app and to create new command.
Exemple of what I want to do:
In terminal: (program name) (a value for exemple a string)And then the program make something depending on the value of the string
What is the easiest way to do this using visual studio 2017?
In Visual Studio you can do
Open your project's property window,
Go to "Configuration Properties" -> "Debugging" -> "Command Arguments"
Put your values to "Command Arguments"
To accept this value in your app, your main function should be of signature like
int main(int argc, char* argv[])
For example "Command Arguments" is set to aaa 123 bbb then the arguments' values are:
argc = 4
argv = {"program_name", "aaa", "123", "bbb"}
Hope this is more convenient than manually giving arguments from command line.
As we know the Query String in web. It's key/value go with the website URL ex: abc.com?myName=stack
For example in PHP, if we want get value of the myName, just do this $_GET['myName']
So, in C++, how can I get it?
in C# I pass an parametter to an *.exe file ( this exe file is C++ code ).
In C++ code, how to get this parametter value .
Build a console application with just the following code:
#include <iostream>
int main(int argc, char** argv)
{
for(int i = 1; i != argc; ++i )
{
std::cout << argv[i] << std::endl;
}
}
Assuming the name of the .exe is mytest.exe, execute it with some arguments, such as:
mytest.exe Hello there.
You should get the following output:
Hello
there.
Hope the simple example makes it clear as to how to process command line arguments in C++.
Have no idea about your situation, but surely you will have realize what parameters do you really need?
If you just need arguments from the command line, simple use the char** argv variable. In complicated cases you can use GNU getopt or even Boost::Program_options (the last is cross-platform);
If you are trying to access environmental variables, use standard getenv functions.
I have a C++ project and a Python project under one solution in Visual Studio. I am reluctant to modify the C++ project, because it is complicated and now complete. I don't want to touch on it any more. So to integrate them, I choose to call the C++ project in Python, instead of the other way round.
I wish to pass the parameters from Python to
int main(int argc, char** argv)
of the C++ project.
How may I do it?
The arguments of main() are the command-line arguments of the program. So if you do for example this in Python:
subprocess.Popen(['myCppprogram.exe', 'foo', 'bar'], ...)
then the following will hold in main():
int main(int argc, char** argv)
{
assert(argc == 3);
assert(argv[1] == std::string("foo");
assert(argv[2] == std::string("bar");
}
According to what i have understood from your question, you want to call a .exe file from python and pass arguments to the C++ file.
import subprocess
program = 'path to your exe file'
argument = "0"
subprocess.call([program, argument])
This will execute the .exe from python and the arguments passed can be read in C++ main as members of the array argv.
In VS2010 I set command line arguments in the project settings->Debugging->Command line arguments:
-d 48000 1 -raw test1.opus test1_decoded.raw
However, when I debug the project and have a look at the argv[] in
int main(int argc, char *argv[])
{
}
... I can see that these command line arguments are missing.
The command line argument argv instead has only the path to the exe that is just being debugged. I see that if I move the mouse over the argv.
Does anybody have an idea what I might have done wrong?
Thank you for the help.
However, when I debug the project and have a look at the argv[]...
Per your description and code, I'm assuming that you are hovering your mouse over argv or looking at it in the watch window. argv is a pointer to pointer to char. The debugger does not know how many elements it contains. It will show you the first element i.e.,*argv`), but no more because there is simply no safe, standard way of doing so.
Your command line arguments are there, but the debugger cannot figure out how many elements to display in the UI. Look at the value of argc; that should match your number of arguments +1 for the path to your executable.