Aug 25, 2014 at 8:12am UTC
I am wondering how to use Open With... to copy path, i used:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include "stdafx.h"
#include <iostream>;
using namespace std;
int _tmain(int argc, _TCHAR *argv[])
{
if (!argv[1]){
std::cout<<"No Variables.\r\n" ;
system("PAUSE" );
return 0;
std::exit;
}
std::cout<<"Path: " <<argv[1]<<"\r\n" ;
system("PAUSE" );
return 0;
}
That say No variables, Or Path: 30006
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include "stdafx.h"
#include <iostream>;
using namespace std;
int _tmain(int argc, char *argv[])
{
if (!argv[1]){
std::cout<<"No Variables.\r\n" ;
system("PAUSE" );
return 0;
std::exit;
}
std::cout<<"Path: " <<argv[1]<<"\r\n" ;
system("PAUSE" );
return 0;
}
Output is No variables or Path: C
Thanks in forward.
Last edited on Aug 25, 2014 at 8:02pm UTC
Aug 25, 2014 at 6:35pm UTC
Dear @Computergeek01
I am making Runtime Evernoment whish will run: system("java -jar mylang.jar " << argv[1];
where argv[1] represents path, and run it.
That will run JAVA command, and run evernoment. Thanks for this.
P.S.
How to add specific thing to PATH using C++ console app?
Aug 25, 2014 at 6:46pm UTC
Take the string literal data that you are trying to prepend to the path and make it into an std::string. From there you have your choice of the "+=" operator or the "std::string.append()" function to add the path passed in to your string. Then, if you insist on using the "system()" function, you'll need to use the "std::string.c_str()" member function to pass the result on.
Aug 25, 2014 at 6:50pm UTC
system("java -jar mylang.jar " << argv[1];
That's a pretty big security hole. Someone could inject any code they wanted into that.
Aug 25, 2014 at 6:54pm UTC
Ok, @giblit is there alternative?
@Computergeek01 is it gong to be C://myfile.mylang, or just C, like with cout, with char *argv[] or, _TCHAR *argv[]
P.S.
It is _TCHAR. Thanks. and java thing??
P.S. 2
And PATH thing??
Last edited on Aug 25, 2014 at 6:56pm UTC
Aug 25, 2014 at 7:10pm UTC
The string that you receive from argv[1] will be what ever you pass to it. I guess I don't understand the question.
Aug 25, 2014 at 7:12pm UTC
@Computergeek append dont work, can u give me example code?
@giblit how to run that java program? Since java is under path.
Aug 25, 2014 at 7:17pm UTC
1 2 3 4
std::string Command = "java -jar mylang.jar " ;
Command.append(argv[1]);
//THEN LAUNCH YOUR CODE
This is something that a batch file could do. Is this academic?
EDIT: Don't forget to include the 'string' header file. That might be why it's not working for you.
Last edited on Aug 25, 2014 at 7:18pm UTC
Aug 25, 2014 at 7:19pm UTC
error C2664: 'std::basic_string<_Elem,_Traits,_Ax> &std::basic_string<_Elem,_Traits,_Ax>::append(const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 1 from '_TCHAR *' to 'const std::basic_string<_Elem,_Traits,_Ax> &'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> Reason: cannot convert from '_TCHAR *' to 'const std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
and, its at Command., at dot. And too few arguements.
Included firstly string, then string.h
Also, it needs argv[1] then some int by constructor.
Last edited on Aug 25, 2014 at 7:22pm UTC
Aug 25, 2014 at 7:25pm UTC
Sorry, I assumed that you read giblet's post. _TCHAR is a wide character string. If you are using wide characters, then you need wide strings to accommodate them.
This: std::string Command = "java -jar mylang.jar " ;
Should become this: std::wstring Command = L"java -jar mylang.jar " ;
Take note, the "system()" function does not take wide strings as an argument.
Last edited on Aug 25, 2014 at 7:25pm UTC
Aug 25, 2014 at 7:26pm UTC
Oooooo, thats ok, work, is it adding path to end, and CreateProcess
I didnt understanded you good at start,
Aug 25, 2014 at 8:01pm UTC
What to do with CreateProcess, @giblit
Aug 25, 2014 at 8:51pm UTC
Sorry for annoyingness, but i need example, i dont understand it, little newer to c++, but i wanna my RE as first project at C++