Ruby behaves differently in windows task scheduler - ruby

Ruby won't recognize directories when run from the task scheduler. I've had similar issues with ruby when running from the windows task scheduler.
Can anyone explain why ruby behaves this way when run from the Windows Task Scheduler?
Consider the following directory on my desktop
(d)test
----(d)One
----(d)Two
----(d)Three
----(f)dirs.rb
----(f)log.log
(d) = Directory
(f) = file
Consider the following Ruby script.
require 'logger'
log = Logger.new("C:/Users/crosson.Z7NETWORKS/Desktop/test/log.log", 'daily')
log.level = Logger::INFO
Dir.new("C:/Users/crosson.Z7NETWORKS/Desktop/test").each do |file|
log.info "%7s a dir? %s" % [file, File.directory?(file)]
end
Below is a result of the log when run from the command line.
I, [2011-08-30T12:50:47.700617 #5356] INFO -- : . a dir? true
I, [2011-08-30T12:50:47.700617 #5356] INFO -- : .. a dir? true
I, [2011-08-30T12:50:47.700617 #5356] INFO -- : dirs.rb a dir? false
I, [2011-08-30T12:50:47.700617 #5356] INFO -- : log.log a dir? false
I, [2011-08-30T12:50:47.700617 #5356] INFO -- : One a dir? true
I, [2011-08-30T12:50:47.700617 #5356] INFO -- : Three a dir? true
I, [2011-08-30T12:50:47.701617 #5356] INFO -- : Two a dir? true
Below is a result of the log when run from the task scheduler
I, [2011-08-30T13:03:07.187316 #5972] INFO -- : . a dir? true
I, [2011-08-30T13:03:07.188316 #5972] INFO -- : .. a dir? true
I, [2011-08-30T13:03:07.188316 #5972] INFO -- : dirs.rb a dir? false
I, [2011-08-30T13:03:07.188316 #5972] INFO -- : log.log a dir? false
I, [2011-08-30T13:03:07.188316 #5972] INFO -- : One a dir? false
I, [2011-08-30T13:03:07.188316 #5972] INFO -- : Three a dir? false
I, [2011-08-30T13:03:07.188316 #5972] INFO -- : Two a dir? false
Notice that my directories, One, Two and Three are no longer considered directories. What gives?

This is a complete guess, but what user is the Windows Task Scheduler using to run the script? I dimly remember issues with the task scheduler due to that process not having the same constellation of rights as me.

Related

How to automatically replace a special character in the installation path on Inno Setup?

I am making a mod for a game. My problem is that in the windows registry the path of the game has a character that is different from the path that it should be.
Windows Registry:
D:\SteamLibrary\steamapps\common[NINJA GAIDEN Master Collection] NINJA GAIDEN Σ
Correct path:
D:\SteamLibrary\steamapps\common[NINJA GAIDEN Master Collection] NINJA GAIDEN Σ
[Setup]
DefaultDirName={code:GetInstallationPath}
[Code]
var
InstallationPath: string;
function GetInstallationPath(Param: string): string;
begin
{ Detected path is cached, as this gets called multiple times }
if InstallationPath = '' then
begin
if RegQueryStringValue(
HKLM64, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 1580780',
'InstallLocation', InstallationPath) then
begin
Log('Detected Steam installation: ' + InstallationPath);
end
else
begin
InstallationPath := 'C:\games';
Log('No installation detected, using the default path: ' + InstallationPath);
end;
end;
Result := InstallationPath;
end;
How do I make it for Inno Setup replace the wrong symbol in the installation path?
"...[NINJA GAIDEN Master Collection] NINJA GAIDEN Σ"
to
"...[NINJA GAIDEN Master Collection] NINJA GAIDEN Σ"

Unable to open file in 'r' mode

I'm trying to read from a text file in my synthesis code. However, I get an error when I try to open a file that does exist.
I have tried placing the text file in various folders because I figured the problem was that the program is unable to find the text file. None of these different positions have worked.
type chunk is array (INPUTNUM downto 0) of std_logic_vector (WIDTH-1 downto 0);
impure function ReadfromFile (FileName: in string) return chunk is
FILE IN_FILE : text open read_mode is FileName;
variable BUFF : line;
variable val : chunk;
begin
for i in 0 to INPUTNUM loop
readline (IN_FILE, BUFF);
read (BUFF, val(i));
end loop;
return val;
end function;
signal w : chunk := ReadfromFile("neuron_text.txt");
I expected the file to be read and the values to be stored in the w signal. However, when I run the RTL analysis I get the error : "[Synth 8-3302] unable to open file 'neuron_text.txt' in 'r' mode" as well as "[Synth 8-421] mismatched array sizes in rhs and lhs of assignment". I assume the second error is a result of the first one though.
Vivado runs four, five or six levels of hierarchy lower down than you think (depending on the version you're running). Try:
signal w : chunk := ReadfromFile("../../../../neuron_text.txt");
or
signal w : chunk := ReadfromFile("../../../../../neuron_text.txt");
or even
signal w : chunk := ReadfromFile("../../../../../../neuron_text.txt");
If this still doesn't work, try opening a file for writing, seeing where it gets creating and using that information to your advantage.

Random number generator in VHDL

I'm designing a test bench and I need to create a random sequence of bits for one of the system's inputs which is normally controlled by the user.
I also want this sequence of bits not being in the same order every time I run the simulation.
I cannot use a PRNG since its initial state will be predefined meaning it while produce the same numbers every time. I also used the uniform function but I had the same issue.
RAND_GEN : process(clk) is
variable seed1, seed2 : positive := 1;
variable re : real;
begin
if rising_edge(clk) then
uniform(seed1, seed2, re);
if (re < 0.5) then
rand_bit <= '0';
else
rand_bit <= '1';
end if;
end if;
end process;
Is there any alternatives for this problem?
Testing with randomly generated inputs is a powerful tehnique and is the technique commonly used to verify ICs these days. Normally, you would run a test with a known, per-determined seed, whereas you want to be able to generate a varying seed. So, you absolutely MUST record this seed when you run the test and provide a mechanism to run a test using this seed. Otherwise, when you find a bug, you will not be able to test whether you've fixed it. You might find it more useful to a a fixed set of tests with a smaller number of manually-generated seeds.
You could use the linux date command with the %s format specifier, which outputs the number of seconds since 1/1/1970 and redirect that to a file.
date +%s >! seed.txt
Then read the file, eg:
RAND_GEN : process(clk) is
variable seed1, seed2 : positive := 1;
variable re : real;
file F: TEXT;
variable L: LINE;
variable seed_RNG : boolean := false;
begin
if not seed_RNG then
file_open(F, "seed.txt", READ_MODE);
readline (F, L);
read (L, seed1); -- or seed2
file_close(F);
report "seed1 = " & integer'image(seed1);
seed_RNG := true;
end if;
if rising_edge(clk) then
uniform(seed1, seed2, re);
if (re < 0.5) then
rand_bit <= '0';
else
rand_bit <= '1';
end if;
end if;
end process;
I don't know anything of VHDL, but in general I try to avoid randomness in tests. Flaky unit tests, for example, are bad. What's the value of a test that fails only sometimes?
Anyway, supposed you really want to do it, do you have access to a timer? You can initialize the PRNG with the current time as seed. Not cryptographically safe, but probably for this use case good enough.
Just for the record, in case anyone needs something similar, I used the above ideas by creating a do file which first writes the date in a file and then runs the do file of the actual test bench which reads this number as suggested before.
set t [clock seconds]
set outputFile [open date.txt w]
puts $outputFile $t
close $outputFile
do testbench.do

why isn't gearmand processing workers?

I am on Mac OSX (Yosemite)
Installed using homebrew.
➜ ~ brew list gearmand
/usr/local/Cellar/gearman/1.1.12/bin/gearadmin
/usr/local/Cellar/gearman/1.1.12/bin/gearman
/usr/local/Cellar/gearman/1.1.12/homebrew.mxcl.gearman.plist
/usr/local/Cellar/gearman/1.1.12/include/libgearman/gearman.h
/usr/local/Cellar/gearman/1.1.12/include/libgearman-1.0/ (39 files)
/usr/local/Cellar/gearman/1.1.12/lib/libgearman.8.dylib
/usr/local/Cellar/gearman/1.1.12/lib/pkgconfig/gearmand.pc
/usr/local/Cellar/gearman/1.1.12/lib/ (2 other files)
/usr/local/Cellar/gearman/1.1.12/sbin/gearmand
/usr/local/Cellar/gearman/1.1.12/share/man/ (156 files)
Added /usr/local/sbin to my path (.bash-path) so that gearmand is on path.
➜ ~ echo $PATH
/Users/davidvezzani/.rvm/gems/ruby-1.9.3-p551/bin:/Users/davidvezzani/.rvm/gems/ruby-1.9.3-p551#global/bin:/Users/davidvezzani/.rvm/rubies/ruby-1.9.3-p551/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/Users/davidvezzani/.rvm/bin:/Users/davidvezzani/bin
Checking if on path. And it is.
➜ ~ which gearmand
/usr/local/sbin/gearmand
Trying to start up gearmand. I was expecting to see some log statements indicating the server has started and that it's waiting for jobs to process. There's nothing.
➜ ~ gearmand --verbose DEBUG
Is it running?!
501 17847 17693 0 11:24AM ttys017 0:00.01 gearmand --verbose DEBUG
Yes. But I have no idea what it is doing. Let's run one of the examples from gearman-ruby.
rvm use 2.2.0
gem install gearman-ruby
mvim do_reverse.rb
Provide the following content
# reverse_do.rb
require 'rubygems'
require 'gearman'
# Add our servers
servers = ['127.0.0.1:4730']
# Initialize a new client
client = Gearman::Client.new(servers)
puts "Sending job...";
task = Gearman::Task.new('reverse', 'Hello World!', {})
result = client.do_task task
puts "Result: " + result
Run the example client.
➜ work3 ruby reverse_do.rb
D, [2015-07-21T14:00:40.717160 #21521] DEBUG -- : Performing health check for 127.0.0.1:4730 (connected: false)
D, [2015-07-21T14:00:40.717248 #21521] DEBUG -- : Attempt #0 to connect to 127.0.0.1:4730
D, [2015-07-21T14:00:40.718060 #21521] DEBUG -- : Health check response for 127.0.0.1:4730 (connected: true) is [:echo_res, "ping"]
Sending job...
D, [2015-07-21T14:00:40.719181 #21521] DEBUG -- : Available job servers: [#<Gearman::Connection:0x007f960e049b78 #hostname="127.0.0.1", #port=4730, #real_socket=#<TCPSocket:fd 7>>]
D, [2015-07-21T14:00:40.719215 #21521] DEBUG -- : Using 127.0.0.1:4730 (connected: true) to submit job
D, [2015-07-21T14:00:40.719473 #21521] DEBUG -- : Got job_created from 127.0.0.1:4730 (connected: true)
The client seems to run, but I should see "Result" at some point, but I am not seeing that. What am I missing?
From the Gearman documentation:
This document assumes a high-level understanding of the role of the job server, clients, and workers.
Since there are three players involved here, when running an example, at least one Gearman job server (this example shows running 2),
(Execute from terminal:)
gearmand --verbose DEBUG -p 4730
gearmand --verbose DEBUG -p 4731
... start up your workers,
# worker.rb
require 'rubygems'
require 'logger'
require 'gearman'
servers = ['localhost:4730', 'localhost:4731']
w = Gearman::Worker.new(servers)
logger = Logger.new(STDOUT)
# Add a handler for a "sleep" function that takes a single argument, the
# number of seconds to sleep before reporting success.
w.add_ability("sleep") do |data,job|
seconds = 10
logger.info "Sleeping for #{seconds} seconds"
(1..seconds.to_i).each do |i|
sleep 1
# Report our progress to the job server every second.
job.report_status(i, seconds)
end
# Report success.
true
end
w.add_ability("blah") do |data,job|
logger.info "Blah, blah, blah..."
# Report our progress to the job server every second.
job.report_status(1, 1)
# Report success.
true
end
loop { w.work }
(Execute from terminal:)
ruby worker.rb
... and have a client push a job on the stack.
# reverse_do.rb
require 'gearman'
servers = ['localhost:4730', 'localhost:4731']
client = Gearman::Client.new(servers)
taskset = Gearman::TaskSet.new(client)
task = Gearman::Task.new('sleep', 20)
task.on_complete {|d| puts "Finished with client: #{d}" }
task2 = Gearman::Task.new('blah')
task2.on_complete {|d| puts "Finished with client for blah: #{d}" }
taskset.add_task(task)
taskset.add_task(task2)
taskset.wait(100)
(Execute from terminal:)
ruby reverse_do.rb
Server results.
Even through I have turned on verbosity to DEBUG, I'm seeing no logging in the terminal.
Worker results.
➜ work3 ruby worker.rb
D, [2015-07-21T15:04:34.868178 #22866] DEBUG -- : Performing health check for localhost:4730 (connected: false)
D, [2015-07-21T15:04:34.868258 #22866] DEBUG -- : Attempt #0 to connect to localhost:4730
D, [2015-07-21T15:04:34.869435 #22866] DEBUG -- : Health check response for localhost:4730 (connected: true) is [:echo_res, "ping"]
D, [2015-07-21T15:04:34.869471 #22866] DEBUG -- : Performing health check for localhost:4731 (connected: false)
D, [2015-07-21T15:04:34.869493 #22866] DEBUG -- : Attempt #0 to connect to localhost:4731
D, [2015-07-21T15:04:34.869962 #22866] DEBUG -- : Health check response for localhost:4731 (connected: true) is [:echo_res, "ping"]
D, [2015-07-21T15:04:34.870030 #22866] DEBUG -- : Announced ability sleep
D, [2015-07-21T15:04:34.870107 #22866] DEBUG -- : Announced ability sleep
D, [2015-07-21T15:04:34.870160 #22866] DEBUG -- : Announced ability blah
D, [2015-07-21T15:04:34.870193 #22866] DEBUG -- : Announced ability blah
D, [2015-07-21T15:04:34.870238 #22866] DEBUG -- : Sending GRAB_JOB to localhost:4730 (connected: true)
I, [2015-07-21T15:04:34.870417 #22866] INFO -- : Got NO_JOB from localhost:4730 (connected: true)
D, [2015-07-21T15:04:34.870444 #22866] DEBUG -- : Sending GRAB_JOB to localhost:4731 (connected: true)
I, [2015-07-21T15:04:34.870620 #22866] INFO -- : Got NO_JOB from localhost:4731 (connected: true)
I, [2015-07-21T15:04:34.870657 #22866] INFO -- : Sending PRE_SLEEP and going to sleep for 30 second(s)
D, [2015-07-21T15:04:34.870764 #22866] DEBUG -- : Polling on 2 available server(s) with a 30 second timeout
D, [2015-07-21T15:04:53.263702 #22866] DEBUG -- : Received NOOP while sleeping... waking up!
D, [2015-07-21T15:04:53.263801 #22866] DEBUG -- : Sending GRAB_JOB to localhost:4730 (connected: true)
I, [2015-07-21T15:04:53.264074 #22866] INFO -- : Got NO_JOB from localhost:4730 (connected: true)
D, [2015-07-21T15:04:53.264101 #22866] DEBUG -- : Sending GRAB_JOB to localhost:4731 (connected: true)
I, [2015-07-21T15:04:53.264367 #22866] INFO -- : Got JOB_ASSIGN with handle H:Davids-iMac.local:6 and 0 byte(s) from localhost:4731 (connected: true)
I, [2015-07-21T15:04:53.264399 #22866] INFO -- : Blah, blah, blah...
D, [2015-07-21T15:04:53.264443 #22866] DEBUG -- : Sending WORK_COMPLETE for H:Davids-iMac.local:6 with 4 byte(s) to localhost:4731 (connected: true)
D, [2015-07-21T15:04:53.264491 #22866] DEBUG -- : Sending GRAB_JOB to localhost:4731 (connected: true)
I, [2015-07-21T15:04:53.264710 #22866] INFO -- : Got NO_JOB from localhost:4731 (connected: true)
I, [2015-07-21T15:04:53.264735 #22866] INFO -- : Sending PRE_SLEEP and going to sleep for 30 second(s)
D, [2015-07-21T15:04:53.264795 #22866] DEBUG -- : Polling on 2 available server(s) with a 30 second timeout
D, [2015-07-21T15:04:53.265126 #22866] DEBUG -- : Received NOOP while sleeping... waking up!
D, [2015-07-21T15:05:03.269974 #22866] DEBUG -- : Sending GRAB_JOB to localhost:4730 (connected: true)
I, [2015-07-21T15:05:03.270372 #22866] INFO -- : Got JOB_ASSIGN with handle H:Davids-iMac.local:4 and 2 byte(s) from localhost:4730 (connected: true)
I, [2015-07-21T15:05:03.270405 #22866] INFO -- : Sleeping for 10 seconds
D, [2015-07-21T15:05:13.301296 #22866] DEBUG -- : Sending WORK_COMPLETE for H:Davids-iMac.local:4 with 4 byte(s) to localhost:4730 (connected: true)
D, [2015-07-21T15:05:13.301415 #22866] DEBUG -- : Sending GRAB_JOB to localhost:4730 (connected: true)
I, [2015-07-21T15:05:13.301655 #22866] INFO -- : Got NO_JOB from localhost:4730 (connected: true)
D, [2015-07-21T15:05:13.301696 #22866] DEBUG -- : Sending GRAB_JOB to localhost:4731 (connected: true)
I, [2015-07-21T15:05:13.301920 #22866] INFO -- : Got NO_JOB from localhost:4731 (connected: true)
I, [2015-07-21T15:05:13.301951 #22866] INFO -- : Sending PRE_SLEEP and going to sleep for 30 second(s)
D, [2015-07-21T15:05:13.302023 #22866] DEBUG -- : Polling on 2 available server(s) with a 30 second timeout
Client results.
➜ work3 ruby reverse_do.rb
D, [2015-07-21T14:55:09.896887 #22800] DEBUG -- : Performing health check for localhost:4730 (connected: false)
D, [2015-07-21T14:55:09.896973 #22800] DEBUG -- : Attempt #0 to connect to localhost:4730
D, [2015-07-21T14:55:09.898392 #22800] DEBUG -- : Health check response for localhost:4730 (connected: true) is [:echo_res, "ping"]
D, [2015-07-21T14:55:09.898428 #22800] DEBUG -- : Performing health check for localhost:4731 (connected: false)
D, [2015-07-21T14:55:09.898451 #22800] DEBUG -- : Attempt #0 to connect to localhost:4731
D, [2015-07-21T14:55:09.898963 #22800] DEBUG -- : Health check response for localhost:4731 (connected: true) is [:echo_res, "ping"]
D, [2015-07-21T14:55:09.899153 #22800] DEBUG -- : Available job servers: [#<Gearman::Connection:0x007fb6a309fd88 #hostname="localhost", #port=4730, #real_socket=#<TCPSocket:fd 9>>, #<Gearman::Connection:0x007fb6a309e258 #hostname="localhost", #port=4731, #real_socket=#<TCPSocket:fd 10>>]
D, [2015-07-21T14:55:09.899182 #22800] DEBUG -- : Using localhost:4731 (connected: true) to submit job
D, [2015-07-21T14:55:09.899464 #22800] DEBUG -- : Got job_created from localhost:4731 (connected: true)
D, [2015-07-21T14:55:19.903692 #22800] DEBUG -- : Received WORK_STATUS for H:Davids-iMac.local:5: 1 / 1
D, [2015-07-21T14:55:19.903789 #22800] DEBUG -- : Received WORK_COMPLETE for H:Davids-iMac.local:5
Finished with client for blah: true
D, [2015-07-21T14:55:19.903933 #22800] DEBUG -- : Available job servers: [#<Gearman::Connection:0x007fb6a309fd88 #hostname="localhost", #port=4730, #real_socket=#<TCPSocket:fd 9>>, #<Gearman::Connection:0x007fb6a309e258 #hostname="localhost", #port=4731, #real_socket=#<TCPSocket:fd 10>>]
D, [2015-07-21T14:55:19.903993 #22800] DEBUG -- : Using localhost:4730 (connected: true) to submit job
D, [2015-07-21T14:55:19.904225 #22800] DEBUG -- : Got job_created from localhost:4730 (connected: true)
D, [2015-07-21T14:55:30.908445 #22800] DEBUG -- : Received WORK_STATUS for H:Davids-iMac.local:3: 1 / 10
D, [2015-07-21T14:55:31.911152 #22800] DEBUG -- : Received WORK_STATUS for H:Davids-iMac.local:3: 2 / 10
D, [2015-07-21T14:55:32.914036 #22800] DEBUG -- : Received WORK_STATUS for H:Davids-iMac.local:3: 3 / 10
D, [2015-07-21T14:55:33.916782 #22800] DEBUG -- : Received WORK_STATUS for H:Davids-iMac.local:3: 4 / 10
D, [2015-07-21T14:55:34.919513 #22800] DEBUG -- : Received WORK_STATUS for H:Davids-iMac.local:3: 5 / 10
D, [2015-07-21T14:55:35.922062 #22800] DEBUG -- : Received WORK_STATUS for H:Davids-iMac.local:3: 6 / 10
D, [2015-07-21T14:55:36.926507 #22800] DEBUG -- : Received WORK_STATUS for H:Davids-iMac.local:3: 7 / 10
D, [2015-07-21T14:55:37.930245 #22800] DEBUG -- : Received WORK_STATUS for H:Davids-iMac.local:3: 8 / 10
D, [2015-07-21T14:55:38.930387 #22800] DEBUG -- : Received WORK_STATUS for H:Davids-iMac.local:3: 9 / 10
D, [2015-07-21T14:55:39.933860 #22800] DEBUG -- : Received WORK_STATUS for H:Davids-iMac.local:3: 10 / 10
D, [2015-07-21T14:55:39.933983 #22800] DEBUG -- : Received WORK_COMPLETE for H:Davids-iMac.local:3
Finished with client: true
Understanding the high-level concepts will be important so it is understood what order the scripts should be executed after the gearmand servers are started so that a working example can be successfully executed.

I am unsure of the correct syntax to use in eiffel?

I have a feature
feature --compare
is_less alias "<" (other: MONEY): BOOLEAN
-- Is current money less than `other'?
local
temp: BOOLEAN
do
temp := cents < other.cents
Result := temp
end
It just checks two number of cents (cents < other.cents) is greater than.
I cannot get the Result to return true even if i set it too true:
Result := temp -----> Result := true
I am using 13.11 and it works well for me.
is_less alias "<" (other: like Current): BOOLEAN
require
not_void: other /= Void
do
Result := cents < other.cents
end
In another class I call this function and it works as expected.
do_compare
local
m1, m2: MONEY
do
create m1.make_from_volume (1)
create m2.make_from_volume (2)
print(m1.is_less (m2))
end
So I wonder how did not check if the Result is True or not? How did you pass the argument to it?

Resources