-
Notifications
You must be signed in to change notification settings - Fork 14
Fails to parse ping output when OS language is set to Chinese #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
like this : |
This looks to be related to flutter/flutter#81666. If you have resources in your project with non-English names, you may want to look at flutter/flutter#81666 (comment). |
But this error only occurs when I use the method in this package |
Can you provide steps to reproduce the error? |
class _MyHomePageState extends State {
} |
yes |
What is the default language of the OS that you are running this dart application on? If it's anything other than english, you will need to specify a character encoder and a different regex parser as documented in the readme. The reason for this is that this library actually calls the platform's ping binary and runs it as a process. It then parses/interprets the output. So it needs to know how to correctly do that. |
i see!!The default language of the operating system of this dart application is Chinese. |
I'm sorry,I have to ask you a question again. I can't understand this parser. How to modify it? |
Open a command prompt or terminal on the OS (not using dart) and run a ping like this: Look at the output. For each line of output, you'll need to adapt the regex parser. If you post the output of the ping command here, I can try to help you tomorrow. It's getting late here so I probably won't be able to respond much more. |
Thank you very much. Have a good rest |
Can you post the output of a standard ping command on your system's terminal or command line? |
yes , this is result : 正在 Ping www.a.shifen.com [110.242.68.4] 具有 32 字节的数据: 110.242.68.4 的 Ping 统计信息: C:\Users\NH-Studio> |
|
onPressed: () { |
I do this, but it still gives errors |
For the encoding, try it with the "allowMalformed" option:
|
I have tried this way. Although there is no error, there is no result feedback |
Okay that probably means the regex isn't picking up anything. Sorry it's taken me so long to look into this. I just have a lot going on. Thanks for your patience |
Thank you for taking the time to answer my question. Is my regex writing wrong? I tried to change the computer language to English,it can work, but I could not receive the results in Chinese |
Try this: final parser = PingParser(
responseStr: RegExp(r'来自'),
responseRgx: RegExp(r'来自 (?<ip>.*)的回复: 字节=(?:\d+) 时间=(?<time>\d+)ms TTL=(?<ttl>\d+)'),
summaryStr: RegExp(r'丢失'),
summaryRgx: RegExp(r'已发送 = (?<tx>\d+),已接收 = (?<rx>\d+),丢失 = (?:\d+)'),
timeoutStr: RegExp(r'请求超时'),
unknownHostStr: RegExp(r'请求找不到主机')); |
I'm sorry,Still no result |
|
I just took the copy of your ping output and put it into here: https://regex101.com/r/aEpqAi/1 I then tried to modify the regex parser to fit the output you gave me. Since I can't read Chinese, it's possible that I over-matched some of the text. I would recommend playing around with it on regex101 to see if you can create a better parsing string. Beyond that, I'm not sure how much I can help until someone can take a look who can debug the library and reads Chinese as well. |
I debugged the code.I found out that the error comes from the decoder. // base_ping.dart
import 'package:fast_gbk/fast_gbk.dart';
// .transform(encoding.decoder)
.transform(gbk.decoder) final parser = PingParser(
responseStr: RegExp(r'来自'),
responseRgx: RegExp(r'来自 (?<ip>.*) 的回复: 字节=(?:\d+) 时间=(?<time>\d+)ms TTL=(?<ttl>\d+)'),
summaryStr: RegExp(r'丢失'),
summaryRgx: RegExp(r'已发送 = (?<tx>\d+),已接收 = (?<rx>\d+),丢失 = (?:\d+)'),
timeoutStr: RegExp(r'请求超时'),
unknownHostStr: RegExp(r'请求找不到主机'),
); |
I tried another way to solve the problem.No need to use parser. // windows_ping.dart
...
@override
Future<Process> get platformProcess async => await Process.start(
'chcp',
['437', '&&', ipv6 ? 'ping6' : 'ping', ...params, host],
environment: locale,
runInShell: true,
);
... |
This is actually a really neat workaround. Thanks for sharing! I'm going to look into including this natively in the package. |
Thanks for the discussion. |
Thank you. This works well. |
1.引入 import 'package:fast_gbk/fast_gbk.dart'; |
This should now be fixed through the use of the final ping = Ping('google.com', forceCodepage: true); |
I will report an error after importing
The text was updated successfully, but these errors were encountered: