Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


lastmod function relying on shell/command line

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
zxuiji
Advanced Cheater
Reputation: 1

Joined: 26 Sep 2016
Posts: 70

PostPosted: Fri Dec 28, 2018 5:43 am    Post subject: lastmod function relying on shell/command line Reply with quote

Not strictly cheat engine related but probably useful anyways, my problem is I'm trying to get the last modification date of files as part of an effort to make a makefile.lua for unrelated projects and provide some barebone functionality that makefiles normally provide, this here is the code I have:
Code:

local nsys = { isWindows = ((os.getenv"os" or ""):match"^Windows") }
-- bunch of code irrelevant to the problem
if nsys.isWindows then
  nsys.lastmod = function(name)
    return io.popen('dir /T:M "' .. name .. '"', "r")
  end
else
  nsys.lastmod = function(name)
    return io.popen('stat -c %Y "' .. name .. '"')
  end
end

But it returns a file handle instead of the output, I've work to go to now so I'd thought I'd post the problem here and see what is said by the time I return. Things I'm looking for are both the output problem and (if any) suggestions for other systems.

_________________
Those who do not trust in christ to save them from their sins will only experience hell when their soul is released from it's earthly vessel.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 67

Joined: 06 Jul 2014
Posts: 2143

PostPosted: Fri Dec 28, 2018 9:43 am    Post subject: Reply with quote

Read the manual:
Quote:
...
Starts program prog in a separated process and returns a file handle that you can use to read data from this program (if mode is "r", the default) or to write data to this program (if mode is "w").

Example:
Code:
local f = io.popen('dir /B')
local dir = {}
for entry in f:lines() do
  dir[#dir+1] = entry
end

for i,v in ipairs(dir) do
  print(i,v)
end

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
zxuiji
Advanced Cheater
Reputation: 1

Joined: 26 Sep 2016
Posts: 70

PostPosted: Fri Dec 28, 2018 6:20 pm    Post subject: Reply with quote

Ah, right, that was it, was in rush to close up at that point so didn't give any thought to it. Well I can still wait to see if any other system variants are posted
_________________
Those who do not trust in christ to save them from their sins will only experience hell when their soul is released from it's earthly vessel.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites