GVKun编程网logo

在Windows中,如何让非阻塞的标准inputredirect的pipe道?(windows recvfrom设置非阻塞)

18

本文的目的是介绍在Windows中,如何让非阻塞的标准inputredirect的pipe道?的详细情况,特别关注windowsrecvfrom设置非阻塞的相关信息。我们将通过专业的研究、有关数据的分

本文的目的是介绍在Windows中,如何让非阻塞的标准inputredirect的pipe道?的详细情况,特别关注windows recvfrom设置非阻塞的相关信息。我们将通过专业的研究、有关数据的分析等多种方式,为您呈现一个全面的了解在Windows中,如何让非阻塞的标准inputredirect的pipe道?的机会,同时也不会遗漏关于(<<--3198)2: Redirecting From A File( Piping and redirecting output、1: Appending(Piping and redirecting output )(--->>15071)、6: Piping Output(Piping and redirecting output )、c – Direct3D是否应该在Windows中使用OpenGL?的知识。

本文目录一览:

在Windows中,如何让非阻塞的标准inputredirect的pipe道?(windows recvfrom设置非阻塞)

在Windows中,如何让非阻塞的标准inputredirect的pipe道?(windows recvfrom设置非阻塞)

我有一个Windows C程序,通过redirect的stdinpipe道获取其数据,有点像这样:

./some-data-generator | ./myprogram

问题是我需要能够以非阻塞的方式从stdin读取。 原因是(1)input是一个数据stream,没有EOF ,(2)程序需要随时中止它的stdin-读线程。 当没有数据时fread块,所以这使得它非常困难。

在Unix中这是没有问题的,因为你可以用fcntl和O_NONBLOCK设置文件描述符的阻塞模式。 但是, fcntl在Windows上不存在。

我试过使用SetNamedPipeHandleState :

什么是骨骼的XYZ坐标的性质是什么?

连接到一个在IIS上运行的代码隐藏的COM接口?

WMI调用方法

C ++ RAII问题

多核编程:做什么是必要的?

DWORD mode= PIPE_READMODE_BYTE|PIPE_NowAIT; BOOL ok= SetNamedPipeHandleState(GetStdHandle(STD_INPUT_HANDLE),&mode,NULL,NULL); DWORD err= GetLastError();

但是这个失败与ERROR_ACCESS_DENIED ( 0x5 )。

我不知道还有什么要做的。 这实际上是不可能的(!)还是只是高度混淆? networking上的资源对于这个特殊问题来说相当稀less。

如何执行多个“.ext”与在C#中做的关联应用程序

在WP 8.1上parsing推送

为什么我的程序在启动之前崩溃?

如何在C#中使用Windows服务调用Windows应用程序?

在Windows 7上启用MysqL 5中的查询日志

订单评估,检查是否有输入准备阅读:

对于控制台模式,可以使用GetNumberOfConsoleInputEvents()。

对于管道重定向,可以使用PeekNamedPipe()

您可以使用异步I / O从句柄读取,如ReadFileEx()WIN32调用。 使用CancelIo()在没有输入的情况下终止读取。

请参阅MSDN: http://msdn.microsoft.com/zh-cn/library/aa365468(VS.85).aspx

总结

以上是小编为你收集整理的在Windows中,如何让非阻塞的标准inputredirect的pipe道?全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

(<<--3198)2: Redirecting From A File( Piping and redirecting output

(<<--3198)2: Redirecting From A File( Piping and redirecting output

We''ve seen how to redirect from a command to a file. We can also redirect the other way, from a file to a command. This involves redirecting from thestandard output of the file to the standard inputof the command.

In our last screen, the file beer.txt ends up looking like this:

99 bottles of beer on the wall...

Take one down, pass it around, 98 bottles of

    beer on the wall...

The Linux sort command will sort the lines of a file in alphabetical order. If we pass the -r flag, the lines will be sorted in reverse order.

sort < beer.txt

The above code will sort each of the lines inbeer.txt in order.

Instructions

  • Use the sort command to sort the lines of beer.txt in reverse order

/home/dq$ sort -r < beer.txt                                                    

Take one down,pass it around,98 bottles of beer on the wall...                  

00 bottles of beer on the wall....                      

###################################################################

 

   3: The Grep Command

Sometimes, we''ll want to search through the contents of a set of files to find a specific line of text. We can use the grep command for this.

grep "pass" beer.txt

The above command will print any lines inbeer.txt where the string pass appears, and highlight the string pass.

We can specify multiple files by passing in more arguments:

grep "beer" beer.txt coffee.txt

This will show all lines from either file that contain the string beer.

Instructions

  • Make a file called coffee.txt that has two lines of text in it:

    Coffee is almost as good as beer,
    But I could never drink 99 bottles of it
    
  • Use the grep command to search beer.txt and coffee.txtfor the string bottles of

~$ echo ''Coffee is almost as good as beer,\nBut I could never drink 99 bottles of it'' > coffee.txt
~$ grep "bottles of" beer.txt coffee.txt

 

########################################################################## 

 

       4: Special Characters              

Like we did in the last screen, sometimes we''ll want to execute commands on a set of files. There were only 2 files in the last screen though,beer.txt and coffee.txt. But what if we wanted to search through all 1000 files in a folder? We definitely wouldn''t want to type out all of the names. Let''s say we have the following files in a directory:

beer.txt

beer1.txt

beer2.txt

coffee.txt

better_coffee.txt

If we wanted to search for a string in beer1.txtand beer2.txt, we could use this command:

grep "beer" beer1.txt beer2.txt

We could also use a wildcard character, ?. ? is used to represent a single, unknown character. We could perform the same search we did above like this:

grep "beer" beer?.txt

The wildcard above will match both beer1.txtand beer2.txt. We can use as many wildcards as we want in a filename.

Instructions

  • Create empty files called beer1.txt and beer2.txt.
  • Use grep and the ? wildcard character to search for beer in both beer1.txt and beer2.txt

~$ touch beer1.txt
~$ touch beer2.txt
~$ grep "beer" beer?.txt

####################################################

5: The Star Wildcard

 

We learned about the ? wildcard character in the last screen, but there are also other wildcard characters. Let''s say we again have the following files in a directory:

beer.txt

beer1.txt

beer2.txt

coffee.txt

better_coffee.txt

We can use the * character to match any number of characters, including 0.

grep "beer" beer*.txt

The above command will search for the stringbeer in beer.txt, beer1.txt, andbeer2.txt. We can also use the wildcard to match more than 1 character:

grep "beer" *.txt

The above command will search for the stringbeer in any file that has a name ending in.txt.

We can use wildcards anytime we would otherwise enter a filename. For example:

ls *.txt

The above command will list any files with names ending in .txt in the current directory.

Instructions

  • Use grep and the * wildcard character to search for beer in all the files ending in .txt in the home directory

~$ grep "beer" *.txt

1: Appending(Piping and redirecting output )(--->>15071)

1: Appending(Piping and redirecting output )(--->>15071)

In an earlier mission, we looked at how to redirect output from a command to a file using >. Here''s an example:

 

echo "This is all a dream..." > dream.txt

If the file dream.txt already exists, the above code will overwrite the file with the string This is all a dream.... If the file dream.txtdoesn''t exist, it will be created, and the stringThis is all a dream... will be used as the content. This involves redirecting from thestandard output of the command to the standard input of the file.

If we don''t want to overwrite dream.txt, and we instead want to add to it, we can use >>.

 

echo "Wake up!" >> dream.txt

The above code will append This is all a dream... to the file dream.txt. The file will still be created if it didn''t exist.

Instructions

  • Overwrite the file beer.txt with the string 99 bottles of beer on the wall....
  • Append the string Take one down, pass it around, 98 bottles of beer on the wall... to the file beer.txt

 

~$ echo ''99 bottles of beer on the wall...'' > beer.txt ~$ echo ''Take one down, pass it around, 98 bottles of beer on the wall...'' >> beer.txt

6: Piping Output(Piping and redirecting output )

6: Piping Output(Piping and redirecting output )

The pipe character, |, allows you to send thestandard output from one command to thestandard input of another command. This can be very useful for chaining together commands.

For example, let''s say we had a file calledlogs.txt with 100000 lines. We only want to search the last 10 lines for the string Error. We can use the tail -n 10 logs.txt to get the last 10 lines of logs.txt. We can then use the pipe character to chain it with a grep command to perform the search:

 

tail -n 10 logs.txt | grep "Error"

The above command will search the last 10lines of logs.txt for the string Error.

We can also pipe the output of a Python script. Let''s say we had this script called rand.py:

 

import random

for i in range(10000):

print(random.randint(1,10))

The above script will use the random library to generate a sequence of random integers, ranging in value from 0 to 10, and will print them to the standard output.

This command will run the script, and search each line of output to see if a 9 occurs:

 

python rand.py | grep 9

Any lines that output a 9 will be printed.

Instructions

  • Make a Python script that generates output.
  • Use pipes and grep to search the output of the script

~$ echo -e "import random\nfor i in range(10000):\n print(random.randint(1,10))\n" > rand.py

~$ python rand.py | grep 9

 

#########################################################

7: Chaining Commands

 

If we want to run two commands sequentially, but not pass output between them, we can use&& to chain them. Let''s say we want to add some content to a file, then print the whole file:

 

echo "All the beers are gone" >> beer.txt &&

    cat beer.txt

This will first add the string All the beers are gone to the file beer.txt, then print the entire contents of beer.txt. The && only runs the second command if the first command doesn''t return an error. If we instead tried this:

 

ec "All the beers are gone" >> beer.txt &&

    cat beer.txt

We''d get an error, and nothing would be printed, because we used the command ec instead ofecho.

Instructions

  • Add a line to beer.txt, and then print the contents of the file with cat

 

/home/dq$ echo "All the beers are gone"  >> beer.txt && cat beer.txt            

99 bottles of beer on the wall...                                               

Take one down, pass it around, 98 bottles of beer on the wall...                

All the beers are gone                

 

######################################################

        8: Escaping Characters                             

 

   

There are quite a few special characters that bash uses. A full list can be found here. When you use these characters in a string or a command, and you don''t want them to have a special effect, you may have to escape them.

Escaping tells the shell to not treat the character as special, but to treat it as a plain character instead. Here''s an example:

 

echo ""Get out of here," said Neil Armstrong

    to the moon people." >> famous_quotes

    .txt

The above command won''t work as we intend because the quotes inside the string will be treated as special. But what we want to do is add the quotes into the file.

We use a backslash (\) as an escape character -- if you add a backslash before a special character, the special character is treated like plain text.

 

echo "\"Get out of here,\" said Neil

    Armstrong to the moon people." >>

    famous_quotes.txt

The command above has the double quotes escaped with a backslash, so it will work as we intend.

Instructions

  • Use the echo command to add a double quote character into a file

 

~$ echo "\"Get out of here,\" said Neil Armstrong to the moon people." >> famous_quotes.txt

c – Direct3D是否应该在Windows中使用OpenGL?

c – Direct3D是否应该在Windows中使用OpenGL?

由于微软通常对Direct3D有偏见,因此Direct3D中使用VBO的场景是否比在OpenGL中使用VBO的场景更快,或者是否与图形卡驱动程序相同?
谢谢

解决方法

性能方面,假设出色的GPU驱动程序,总体上没有差别.

尽管DX10解决了这个问题,OpenGL中的一些操作本身就比DirectX9更快.

但使用外部硬件的一个很好的经验法则是,您不是使用API​​来确定性能.

在编写网络代码时,瓶颈是网络适配器,如果您的套接字代码是用.NET编写的,或者是使用一些Python库,则不需要使用.NET,普通的Berkeley套接字.

当编写代码以使用GPU时,GPU是限制因素. DirectX和OpenGL之间的最大区别在于,可能需要一个函数调用或者两个以上的函数来实现某些任务,而且性能成本几乎不存在.在这两种情况下,GPU都会发生什么,因为这是由GPU驱动程序决定的,因为OpenGL和DirectX都尽可能的高效.

有理由更喜欢任何API.

DirectX具有更好的工具支持.微软做得非常好.使用像PIX这样的工具,调试和优化DirectX代码更容易.而微软还提供了助手库D3DX,它提供了许多常用功能的高效实现.

OpenGL具有的优点是它不受特定操作系统的限制. DirectX9仅适用于Windows. DX10及以上版本仅适用于Vista及以上版本.

OpenGL适用于已经编写了OpenGL驱动程序的任何操作系统.

在Windows上,情况有时有点尴尬. Windows本身只是OpenGL的古老实现. (XP与v1.1,我相信,Vista / 7与1.5).

因此,Windows上的OpenGL应用程序依赖于GPU供应商来提供其驱动程序的更新实现. ATI和NVidia提供了非常好的实现,所以这不是一个问题.英特尔的OpenGL驱动程序通常落后于质量和支持功能.

今天的关于在Windows中,如何让非阻塞的标准inputredirect的pipe道?windows recvfrom设置非阻塞的分享已经结束,谢谢您的关注,如果想了解更多关于(<<--3198)2: Redirecting From A File( Piping and redirecting output、1: Appending(Piping and redirecting output )(--->>15071)、6: Piping Output(Piping and redirecting output )、c – Direct3D是否应该在Windows中使用OpenGL?的相关知识,请在本站进行查询。

本文标签: