It is currently May 17th, 2024, 9:49 am

Executing a command, Having trouble!

Get help with creating, editing & fixing problems with skins
User avatar
bobgrosh
Posts: 134
Joined: May 1st, 2011, 10:33 pm

Executing a command, Having trouble!

Post by bobgrosh »

I have a skin directory called timestamp
In the directory I have three files:
Log.txt
Stamp.ini
and Timestamp.pnd


Log.txt contains

Code: Select all

.LOG

(the second line is blank This causes windows to put a timestamp at the bottom of the file every time it is opened or written to.)

The Stamp.ini contains:

Code: Select all

[Rainmeter]
Update=-1

[Metadata]
Author=Bob Grosh
Version=1.0
Information=Writes a START timestamp to the log.txt file.


[Variables]
Height=120

[icon]
Meter=Image
ImageName=#Image#
X=(#Height#/10)
Y=(#Height#/1.4)
W=(#Height#/3.8)
H=(#Height#/3.8)
AntiAlias=1
LeftMouseUpAction=[echo STARTED EVENT >> Log.txt]

If in a command window in windows 7 or 8 I execut the following:
s:\Documents\Rainmeter\Skins\TimeStamp>echo splat >> log.txt
... then I can open the text file and see

Code: Select all

.LOG

2:09 PM 11/5/2012
splat 

2:10 PM 11/5/2012

If I click on the skin, nothing happens,no errors in the Rainmeter Log, and nothing added to the log.txt file.
I expected it to have appended another times stamp to log.txt followed by "STARTED EVENT" (without the quotes).

Is there something I am missing?
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Executing a command, Having trouble!

Post by Kaelri »

The issue is that "echo" is not an independent program or shell command. It's a feature built into Windows' command prompt interface (cmd.exe). Try this instead:

Code: Select all

LeftMouseUpAction=[cmd.exe /C echo STARTED EVENT >> #CURRENTPATH#Log.txt]
Alternatively, you can do this without any external commands using a Lua script. This would have the advantage of being "silent" (i.e. a command prompt window wouldn't flash on the screen every time you write a new log message).

Code: Select all

[Script]
Measure=Script
ScriptFile=Echo.lua
LogFile=Log.txt

Code: Select all

LeftMouseUpAction=!CommandMeasure Script "Echo('STARTED EVENT')"
Echo.lua

Code: Select all

function Initialize()
	Filename = SELF:GetOption('LogFile')
	Filename = SKIN:MakePathAbsolute(Filename)
end

function Echo(Message)
	local Time = os.date('%I:%M %p %m/%d/%Y')
	local File = io.open(Filename, 'a+')
	if File then
		File:write('\n'..Time..'\n'..Message..'\n')
		File:close()
	end
end
User avatar
bobgrosh
Posts: 134
Joined: May 1st, 2011, 10:33 pm

Re: Executing a command, Having trouble!

Post by bobgrosh »

LOL, You guys are going to force me to learn another language. So far I resisted LAU but this time you hooked me.

First,

Code: Select all

LeftMouseUpAction=[cmd.exe /C echo STARTED EVENT >> #CURRENTPATH#Log.txt] 
Doesn't quite work on windows 8.
It does add 'STARTED EVENT' to the log.txt file but it does not add the times/tamp prior to the text.
Aparently, cmd.exe is not quite the same as the windows command prompt. The functionality of identifying the .LOG on the first line and appending the date/time before appending the echoed text does not work. You get the text appended but not the Date/Time. I haven't tried it on windows 7.

Of course, That method could be fixed by adding the time to the echoed text so that Rainmeter puts the date/time and text directly into the log file instead of letting the OS look for the .LOG on the first line and pre-appending the date/time.
In my situation, I also use a short cut that simply opens that same log.txt file and lets me manually add log entries via notepad. They get the time-stamp because Windows opened the file. That gets complicated because this same skin will be used on XP, 7 and 8, some of which would then have two time stamps per entry.

And, as you pointed out, I did get a DOS box flashing up on the screen.

So...
The LAU script does work. It also eliminates the flashing DOS box.
Thanks.

I have to say that people on this forum have tried to get me to start using LAU several times. I always resisted and managed to find a work-around that let me do what I needed in pure Rainmeter skins. This time you convinced me, You :twisted: You.

Thanks.
User avatar
Kaelri
Developer
Posts: 1721
Joined: July 25th, 2009, 4:47 am

Re: Executing a command, Having trouble!

Post by Kaelri »

bobgrosh wrote:Aparently, cmd.exe is not quite the same as the windows command prompt. The functionality of identifying the .LOG on the first line and appending the date/time before appending the echoed text does not work. You get the text appended but not the Date/Time. I haven't tried it on windows 7.
I have to be honest - I've never used or even encountered this timestamping function in Windows, so I'm not sure why it wouldn't work using this method, or what might have changed from Windows 7 to Windows 8.
bobgrosh wrote:I have to say that people on this forum have tried to get me to start using LAU several times. I always resisted and managed to find a work-around that let me do what I needed in pure Rainmeter skins. This time you convinced me, You :twisted: You.
That is the same experience that almost all Rainmeter users - including myself - have been through. I resisted learning Lua for about a year because I was intimidated by having to learn a new language. But believe me, once you start using it, you'll never go back. Especially with the kind of brilliantly insane ways of using Rainmeter that you are known for. :)
User avatar
jsmorley
Developer
Posts: 22633
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Executing a command, Having trouble!

Post by jsmorley »

As far as I know, the %DATE% and %TIME% variables work the same in Win8 as they do in Win7.

c:>echo %DATE% - %TIME% : Some Text >out.txt
nuskatev
Posts: 4
Joined: November 6th, 2012, 11:44 pm

Re: Executing a command, Having trouble!

Post by nuskatev »

Using the [cmd.exe /C echo STARTED EVENT >> #CURRENTPATH#Log.txt] is there anyway one could flush the contents of Log.txt first? - I'm using a similar approach in one of my projects, but I need to write to an empty file each time. (Removing the file is just as good)

Any help would be greatly appreciated!
User avatar
jsmorley
Developer
Posts: 22633
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Executing a command, Having trouble!

Post by jsmorley »

nuskatev wrote:Using the [cmd.exe /C echo STARTED EVENT >> #CURRENTPATH#Log.txt] is there anyway one could flush the contents of Log.txt first? - I'm using a similar approach in one of my projects, but I need to write to an empty file each time. (Removing the file is just as good)

Any help would be greatly appreciated!
If you use ">" instead of ">>" when you pipe to a file, the file is re-created instead of added to.