io

C - how to poll() input without buffering?

天涯浪子 提交于 2021-01-29 07:54:12
问题 I am trying to detect any character typed to stdin (without a newline character). I tried : setvbuf(stdin, NULL, _IONBF); //This returns 0 struct pollfd pfd = {STDIN_FILENO, POLLIN}; while (!poll(pfd, 1, ms)) { /* do some thing, e.g. printf("n\n"); */ } It appears not stop printing when I typed q , but did stop after I hit enter . The system I am working on is arch-linux, compiler is gcc. 回答1: The q is being held up in the kernel's TTY layer driver/buffer because it is in "cooked" mode. In

Exception in thread “main” java.lang.NullPointerException InputStreamReader

青春壹個敷衍的年華 提交于 2021-01-29 06:36:00
问题 Exception in thread "main" java.lang.NullPointerException at java.io.Reader.<init>(Unknown Source) at java.io.InputStreamReader.<init>(Unknown Source) //at InputStreamReader inStream = new InputStreamReader(fis); Also, should I add throws IOException, FileNotFoundException to main or use try{} instead? System.out.print("Enter the filename: "); Scanner stdin = new Scanner(System.in); //Keyboard input String fileName=stdin.nextLine(); FileInputStream fis = null; try { fis = new FileInputStream

How do I listen for a response from shell command in android studio?

跟風遠走 提交于 2021-01-29 01:49:54
问题 In an android terminal emulator I can type the following commands: > su > echo $(</sys/class/power_supply/battery/charge_rate) and depending on how the phone is charging the output will be "None", "Normal" or "Turbo". I would like to be able to retrieve this output and store it as a string value in my program. So I've done a little bit of research into this and the code I came up with is as follows: String chargeRate = "None"; try { Runtime rt = Runtime.getRuntime(); Process process = rt.exec

How do I listen for a response from shell command in android studio?

僤鯓⒐⒋嵵緔 提交于 2021-01-29 01:46:39
问题 In an android terminal emulator I can type the following commands: > su > echo $(</sys/class/power_supply/battery/charge_rate) and depending on how the phone is charging the output will be "None", "Normal" or "Turbo". I would like to be able to retrieve this output and store it as a string value in my program. So I've done a little bit of research into this and the code I came up with is as follows: String chargeRate = "None"; try { Runtime rt = Runtime.getRuntime(); Process process = rt.exec

How does diamond operator work with array as argument

这一生的挚爱 提交于 2021-01-28 10:30:56
问题 I have got an array @address whose zero element contains some strings. I can not find an example diamond operator works with @array as argument. (how it 'split' strings?) use Mojo::Loader qw/ data_section /; my @address = data_section 'main', 'address_strings'; while( my $line = <@address> ) { print $line; } 1; __DATA__ @@ address_strings "010101, УУУ обл., м. Тернопіль, вул. ВВВ, буд. 0101, 01" "020202, ЛЛЛ обл., ААА район, село ФФФ, ВУЛИЦЯ ШШШ, будинок 01" "030303, м.ЮЮЮ, ЮЮЮ р-н, вул. ЛЛЛ,

When the input will stop?

自古美人都是妖i 提交于 2021-01-28 06:58:00
问题 Hi guys i have the following question: string s; std::cout << "give me a string" << std::endl; while (std::cin >> s){ std::cout << "give me a string" << std::endl; } cin.clear(); if s was an integer then i know that if i typed a char then the while would break. If it was an integer and typed a double the same would happened. But what about strings ?? Somewhere I read that in windows (as I am writting at netbeans in windows) you have to press ctrl+z and then it stops as it is taken as a false

interrupt System.console().readLine()?

柔情痞子 提交于 2021-01-28 06:38:27
问题 It seems to me that once a thread starts reading input via System.console().readLine() or System.in.read() , there is absolutely no way in the universe to functionally interrupt the read, except for System.exit() or providing input. interrupt() ing the reading thread does nothing. Even stop() ing it does nothing. close() ing System.in during System.in.read() does nothing until after the read completes by providing input. The read methods don't take any timeout parameters nor time out on their

Writing to a file which is open in read and write mode altering the structure

旧城冷巷雨未停 提交于 2021-01-28 06:19:54
问题 I have a text file, which has the following, contents: joe satriani is god steve vai is god steve morse is god steve lukather is god I wanted to write a code in python, which will change the file lines like: joe satriani is god ,absolutely man .. steve vai is god,absolutely man .. steve morse is god,absolutely man .. steve lukather is god,absolutely man .. I had tried doing such earlier once and I had not gotten the desired outcome. So, first I tried writing a code, which would just append

Read in file with client-side clojurescript/re-frame app

谁说胖子不能爱 提交于 2021-01-28 05:41:02
问题 I'm writing a client-side application which should read in a file, transform its content and then export the result. To do this, I decided on Re-Frame. Now, I'm just starting to wrap my head around Re-Frame and cloujurescipt itself and got the following thing to work: Somewhere in my view functions, I send this whenever a new file gets selected via a simple HTML input. [:input {:class "file-input" :type "file" :on-change #(re-frame/dispatch [::events/file-name-change (-> % .-target .-value)])

How to advance through data from the std::io::Read trait when Seek isn't implemented?

一笑奈何 提交于 2021-01-28 03:05:04
问题 What's the best way to read from a type implementing the std::io::Read trait when the contents of the output isn't important? Possible options I see are: Read single bytes in a loop. Allocate a potentially huge vector and read into that. Something in-between... read into a fixed sized buffer in a loop . The first 2 options don't seem ideal, the third is OK but inconvenient. Does Rust provide a convenient way to achieve this? 回答1: You can use io::copy(), Read::take() and io::sink() to discard