0

I have an LED sign set up with a Windows computer, and am trying to make it display my Linux computer's temperature:

acpitz-virtual-0

Adapter: Virtual device

temp1: +97.7°F (crit = +183.2°F)

Now, here's the batch file on my computer

wget 192.168.1.58/sensor1.txt

I have a windows version of wget in the folder.

type sensor1.txt | findstr /v acpitz-virtual-0 | findstr /v Adapter: > msg.txt
set /p msg= < msg.txt

prismcom.exe usb {HOLD} %msg%

Now my sign flashes the equivalent of

temp1: +97.7°F (crit = +183.2°F)

I need it to flash

+97.7°F,

or even better,

+97.7 F

I've been trying with FIND and FOR and commands like that, but with no luck. How can I modify my string to work?

Thanks!

5
  • "trying with find and for and stuff like that"? I have to remember that for my next technical question (or better yet, interview question answer). I wonder how it would go... "How would you design a linked list?" - "Well, I'd use pointers and nodes and stuff like that and make it work.". Yep - that would do it. BAM! New job with big pay!! :-) Commented Feb 9, 2013 at 4:49
  • Ahem. Correction: I've been trying with FIND and FOR and commands like that, but with no luck. Commented Feb 9, 2013 at 4:50
  • Oh, yes - your correction is much more precise. ;-) 'I'd use "pointers" and "nodes" and stuff like that' is much clearer. Commented Feb 9, 2013 at 4:54
  • Thanks. Can you answer the question too? Commented Feb 9, 2013 at 5:04
  • Sure. :-) Use FOR with tokens= and stuff, and figure out what you can use for tokens to break up the string. Commented Feb 9, 2013 at 5:11

2 Answers 2

4

Say the variable that the temperature is stored in is called "temp", and has the value of "temp1: +97.7°F (crit = +183.2°F)". This little snippet should work wonders...

setlocal enabledelayedexpansion
set dis=!temp:~7,5! F
set check=!temp:~10,1!
if %check% neq . set dis=!temp:~7,6! F

Here is the syntax:

set variable=!variable_to_be_constrained:~offset,amount_of_characters!

One thing I should mention is that the variable "TEMP" (or "temp", capitalization generally doesn't matter too much with .bat files) is a predefined command line variable, and generally those should never be overwritten. However, in this case it's purely for aesthetic purposes and you can change it to whatever you want.

--EDIT-- Added two lines to allow for temperatures over 100 Fahrenheit. Also changed temp to dis.

Sign up to request clarification or add additional context in comments.

1 Comment

+1, But what you do when the temperature is higher than 100.0°F?
0

If you have a Windows version of wget, then you might as well also have a special command to parse the temperature. In C you can easily do what you want:

#include <stdio.h>

int main(void) {
    char buf[1000];
    scanf("temp1: %[+0-9.]", buf);
    printf("%sF", buf);
    return 0;
}

Compile this with any C compiler. Obtain a free one from MinGW (preferred because the compiled code won't require any extra DLLs) or Cygwin (which does require an extra DLL). You can also try Microsoft Visual Studio Express, but it's more hassle.

If the code above is in filter.c, then the command for MinGW or Cygwin will be

gcc filter.c -o filter

This will produce a file called filter.exe, which you can use in your pipeline with

type sensor1.txt | findstr /v acpitz-virtual-0 | findstr /v Adapter: | filter > msg.txt

The moral is that limited tools (like cmd.exe) are often not worth the trouble.

6 Comments

Sorry, but -1. This doesn't answer the question asked, which was "How to split a string with batch commands in Windows". It might be an alternative, like "How do I fix my Honda's check engine light?" "Buy a Toyota" could be a solution. (Or "How do I write this code in C?" "You can use this in Python.") Apples and oranges.
Fair enough, but sometimes the best answer to a question is to say that the question is not the right one. Teaching 23 years will teach you this.
Interesting question: Who's being pedantic in this discussion?
OK. As a teacher of 23 years, please tell me: "How do you say 'What is my name' in French?". I doubt that the answer is "Well, you can say 'What's my name?" in English instead and it will work, because I've been a teacher for 20+ years and that's the better answer."
Clever, but oh come on... Software design entails judgement. Language translation - at least at the level you have asked - absolutely does not. If your question were about tranlating Proust we could have a serious disucssion.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.