互动和便携? [英] Interactive AND Portable?

查看:71
本文介绍了互动和便携?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C中,有没有办法与正在运行的程序进行交互,但仍然使用可移植的代码,至少在linux和Windows之间?


通过互动它可能就像检测一个键一样简单

板命中,这样它就可以调用scanf()。因此,便携式键盘数据

可用例程将满足我的最低要求。但是更多

一般我想知道是否可以编写便携式C代码,允许

用户更改正在运行的程序的执行过程。


谢谢,


Mitchell Timin


-

很多都很顽固为了追求他们选择的道路,很少有人追求目标。 - Friedrich Nietzsche

http://annevolve.sourceforge.net 这就是我现在所做的事情。

人类可以在这个地址给我写信:zenguy at telus dot net

解决方案

< blockquote> Se******@seebelow.nut 潦草地写道:

是有什么方法,在C中,与正在运行的程序交互,但仍然使用可移植的代码,至少在Linux和Windows之间?
通过互动它可能是一个简单的事情,如检测一个键击板,以便它可以调用scanf()。因此,便携式键盘数据可用的例程将满足我的最低要求。但更多
一般来说,我想知道是否可以编写便携式C代码,允许
用户更改正在运行的程序的执行过程。




号。你直接用键盘做任何事情的那一刻,你就可以获得特定于操作系统的土地了,而且你没有希望使用相同的代码工作
Linux和Windows上


使用标准输入流有什么问题?在大多数情况下,来自键盘的是
。这只是必须按Enter键的问题。


-

/ - Joona Palaste(pa ***** @ cc。 helsinki.fi)-------------芬兰-------- \

\-- http://www.helsinki.fi/~palaste --------------- ------规则! -------- /

我正在寻找自己。你有没见过我?"

- Anon


2003年10月30日星期四20:22:35 GMT, Se ****** @ SeeBelow.Nut 写道:

有什么办法,在C中,与正在运行的程序交互,但仍然使用可移植的代码,至少在Linux和Windows之间?


是的,如果您坚持使用stdio I / O功能(即scanf(),printf()和

之类的),您可以轻松实现写一个便携式互动节目。

通过互动它可能是一个简单的事情,如检测一个键击板,以便它可以调用scanf()。


现在你已经脱离了便携性的世界。

1)C没有任何检测的可行方式键盘命中

(C语言甚至不认识这样的事情),并且

2)在Linux(至少)中,交互式程序可以运行/没有/一个

可识别的''键盘''(认为期望脚本,或者只是简单的

脚本)。要求代码检测键盘命中是使

不可移植。

因此,便携式键盘数据可用例程将满足我的最低要求。


这样的存在,以标准I / O例程的形式存在,如scanf()和getc()

但更多
一般我想要知道是否可以编写便携式C代码,允许
用户改变正在运行的程序的执行过程。




当然可以。使用stdio功能。


-

Lew Pitcher

IT顾问,企业技术解决方案

多伦多道明银行金融集团


(表达的意见是我自己的,而不是我的雇主')


Joona I Palaste写道:


Se******@seebelow.nut 潦草地写下了以下:

在C中是否有任何方式与正在运行的程序进行交互,但仍然使用可移植的代码,至少在Linux和Windows之间?


通过交互它可能是一个简单的事情,如检测一个键击板,以便它可以调用scanf()。因此,便携式键盘数据可用的例程将满足我的最低要求。但是更多
一般来说我想知道是否可以编写便携式C代码,允许
用户改变正在运行的程序的执行过程。



你直接使用键盘做任何事情的那一刻,你就会被特定于操作系统的土地所取代,而你却无法在Linux和Windows上使用相同的代码。
>使用标准输入流有什么问题?在大多数情况下来自键盘。这只是必须按Enter键的问题。




我想我不清楚;在等待输入时,我不希望程序无所事事

来自KB。我的程序可能会运行

小时,进行模拟演化。我需要偶尔给它一些

数据,或者做出决定。我不介意它暂停,而

与我互动,但之后必须继续处理。


有没有办法做到这一点标准输入流?


m


-

很多人都顽固地追求他们的道路已经选择了,很少有人在追求这个目标。
。 - Friedrich Nietzsche

http://annevolve.sourceforge.net 就是我现在所做的事情。

人类可以在这个地址给我写信:zenguy at telus dot net


Is there any way, in C, of interacting with a running program, but still
using code that is portable, at least between linux and Windows?

By "interacting" it could be something as simple as detecting a key
board hit so that it could invoke scanf(). So a portable key board data
available routine would satisfy my minimum requirements. But more
generally I want to know if one can write portable C code that allows a
user to change the course of execution of a running program.

Thanks,

Mitchell Timin

--
"Many are stubborn in pursuit of the path they have chosen, few in
pursuit of the goal." - Friedrich Nietzsche

http://annevolve.sourceforge.net is what I''m into nowadays.
Humans may write to me at this address: zenguy at telus dot net

解决方案

Se******@seebelow.nut scribbled the following:

Is there any way, in C, of interacting with a running program, but still
using code that is portable, at least between linux and Windows? By "interacting" it could be something as simple as detecting a key
board hit so that it could invoke scanf(). So a portable key board data
available routine would satisfy my minimum requirements. But more
generally I want to know if one can write portable C code that allows a
user to change the course of execution of a running program.



No. The moment you do anything at all directly with the keyboard, you''re
off to OS-specific land, and you have no hope of the same code working
on Linux and Windows.
What''s wrong with using the standard input stream? In most cases that is
coming from the keyboard. It''s just a matter of having to press Enter.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"I am looking for myself. Have you seen me somewhere?"
- Anon


On Thu, 30 Oct 2003 20:22:35 GMT, Se******@SeeBelow.Nut wrote:

Is there any way, in C, of interacting with a running program, but still
using code that is portable, at least between linux and Windows?
Yes, if you stick with the stdio I/O functions (i.e. scanf(), printf(), and the
like), you can easily write a portable interactive program.
By "interacting" it could be something as simple as detecting a key
board hit so that it could invoke scanf().
Now you''ve taken yourself out of the world of portability.
1) C doesn''t have any portible way of "detecting a keyboard hit"
(the C language doesn''t even recognize such a thing), and
2) In Linux (at least), an "interactive" program may be run /without/ a
recognizable ''keyboard'' at all (thinks "expect" scripts, or just plain
scripting). To require the code to "detect a keyboard hit" is to make
it unportable.
So a portable key board data
available routine would satisfy my minimum requirements.
Such exists, in the form of the standard I/O routines like scanf() and getc()
But more
generally I want to know if one can write portable C code that allows a
user to change the course of execution of a running program.



Yes, of course. Use the stdio functions.

--
Lew Pitcher
IT Consultant, Enterprise Technology Solutions
Toronto Dominion Bank Financial Group

(Opinions expressed are my own, not my employers'')


Joona I Palaste wrote:


Se******@seebelow.nut scribbled the following:

Is there any way, in C, of interacting with a running program, but still
using code that is portable, at least between linux and Windows?


By "interacting" it could be something as simple as detecting a key
board hit so that it could invoke scanf(). So a portable key board data
available routine would satisfy my minimum requirements. But more
generally I want to know if one can write portable C code that allows a
user to change the course of execution of a running program.



No. The moment you do anything at all directly with the keyboard, you''re
off to OS-specific land, and you have no hope of the same code working
on Linux and Windows.
What''s wrong with using the standard input stream? In most cases that is
coming from the keyboard. It''s just a matter of having to press Enter.



I guess I wasn''t clear; I don''t want the program to be doing nothing
while waiting for an "enter" from the KB. My program may be running for
hours, doing simulated evolution. I need to occaisonally give it some
data, or make a decision for it. I don''t mind if it pauses while
interacting with me, but after that it must continue processing.

Is there a way of doing that with the standard input stream?

m

--
"Many are stubborn in pursuit of the path they have chosen, few in
pursuit of the goal." - Friedrich Nietzsche

http://annevolve.sourceforge.net is what I''m into nowadays.
Humans may write to me at this address: zenguy at telus dot net


这篇关于互动和便携?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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