如何从C ++调用另一个进程并传递** numeric ** args? [英] How do I call another process from C++ and pass **numeric** args?

查看:46
本文介绍了如何从C ++调用另一个进程并传递** numeric ** args?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想调用一个可执行文件 - 从我的代码中调用它为A---设置A以获取控制台参数。我当然可以使用例如_spawnl()从我的代码中调用A,并且还可以将字符串作为参数传递。但是整数呢?不,我***不能控制A,所以我无法在A中转换我的字符串。我也可以通过控制台将参数传递给A,但这不是我想要的;我宁愿让它硬编码。

解决方案

当你启动它时,你不能将除字符串以外的任何东西作为参数传递给它 - 系统期望它由人类输入,因为它不知道你的应用程序将如何处理该参数,它不会尝试将字符串处理为更合适的格式。

For例如,您的应用程序可能与参数00000001和1之间存在不同,因此它无法自动将前者转换为整数并将其传递给它。

结果,参数传递机制仅适用于字符串值。所以A必须已经接受整数值的字符串表示并自动处理它们。





让我们再试一次:A有:int x; cin>> x;

当你通过控制台输入1时,这当然很好。我想从我的代码中运行A传递给它1 ___来自代码___。***我无法接触A****我该怎么办?




那你为什么不呢?首先问一下? :笑:



 HWND MyA = FindWindow(_T( < span class =code-string> A),NULL); 
SendMessage(MyA,WM_SETTEXT,NULL,(LPARAM)_T( hello)) ;

应该这样做......如果没有,那么这应该是: SendKeys in C ++ [ ^ ]


I want to call an executable -- call it "A" --- from my code. "A" is set up to take console arguments. I can certainly call "A" from my code using for instance _spawnl(), and can also pass strings as arguments. But what about ints? No, I ***don't*** have control over "A", so I can't convert my strings inside "A". I can also pass the arguments to "A" via the console, but that is not what I want; I'd rather have it hard coded.

解决方案

You can't pass anything other than strings as arguments to an executable when you start it - the system "expects" it to be typed by a human and since it doesn't know what your app is going to do with the argument, it doesn't try to "process" the strings into more appropriate formats.
For example, there may be a different in your app between and argument "00000001" and "1" so it can't automatically convert the former to an integer and pass it through as that.
As a result, the argument passing mechanism is only available for string values. So "A" must already accept the string representation of integer values and process them itself automatically.


"Let's try again: "A" has: int x; cin >> x;
this works of course fine when you enter 1 via the console. I want to run "A" from my code passing to it 1 ___from code___. *** I CANT TOUCH "A" **** How do I do it?"


Well why didn't you ask that in the first place? :laugh:

HWND MyA= FindWindow(_T("A"), NULL);
SendMessage(MyA, WM_SETTEXT, NULL, (LPARAM)_T("hello"));

Should do it...if it doesn't, then this should: SendKeys in C++[^]


这篇关于如何从C ++调用另一个进程并传递** numeric ** args?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆