Is the RoboRIO restricted from writing and reading files?

Hello, this is our teams first year competing in the FRC (so bear with me ;)) and we are very excited.

Straight to my question…

I have noticed that I am unable to read or write from files in the RoboRIO.

I first executed a writing program in Java. It returned a “Permission Denied.”
I ssh’ed and chmod -R 777 the root directory. This did not fix the problem.

Initial Java code:


try {
	File file = new File("locations.txt");
	file.createNewFile();
	FileOutputStream oFile = new FileOutputStream(file, false);

	String content = "content";

	oFile.write(content.getBytes());
	oFile.flush();
	oFile.close();
	System.out.println("success");
} catch (IOException e) {
	System.out.println("error: " + e.getMessage());
}


Next I decided to write a bash script that could handle the reading and writing. It is called from the default Java program. Interestingly, the bash program works fine in an ssh portal, but fails to read or write from the Java program.

Calling the bash script:


try {
	Runtime runtime = Runtime.getRuntime();
	Process process = runtime.exec("echo \"hello world\" >> /home/lvuser/log.txt");
	final BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
	String line = null;
	while ((line = reader.readLine()) != null) {
		System.out.println("process_output: " + line);
	}
	reader.close();
					  
} catch (IOException e) {
	System.out.println("error " + e.getMessage());
}

Contents of writer.sh:


#!/bin/bash
if  "$1" == 'clear' ]; then
	rm -rf "log.txt"
elif  "$1" == 'read' ]; then
	cat "log.txt"
else
	str="$*"
	echo "$str" >> "log.txt"
	echo $str
fi


So is the RoboRIO restricted from writing and reading files?

Thank you for your time,

Max

1 Like

From the error message you reported, I’m guessing the working directory is “/” or some location that the roborio process does not have write access to.

Try using the full path the the location you want to write to:


try { 
    File file = new File("/home/lvuser/locations.txt"); 
    file.createNewFile(); 
    FileOutputStream oFile = new FileOutputStream(file, false); 

    String content = "content"; 

    oFile.write(content.getBytes()); 
    oFile.flush(); 
    oFile.close(); 
    System.out.println("success"); 
} catch (IOException e) { 
    System.out.println("error: " + e.getMessage()); 
}  

As a side note, after creating these files, I think you should be able to quickly grab them off the roborio using a browser and a FTP URL like: ftp://10.8.68.2/home/lvuser (substitute your roboRIO’s name or IP address for 10.8.68.2).

I am not certain why you were unable to exec a process (though I have never tried that).

I’m actually having the same issue from C++ this year, using snippets of code that have worked in previous years. Has the user that the Robot Program runs under changed, I wonder?

We’re checking if a file exists to determine if we’re running on the competition bot or the practice bot, and we haven’t had any issues.

We don’t have any problem writing files on the RoboRIO. In fact, we are writing our trace log files to /home/lvuser/tracelog for logging events during autonomous. Note that RoboRIO is running a Linux OS so depending on which folder you are writing your file to, in general, since your robot is “logon” to the lvuser, you should have write privilege in /home/lvuser. So try creating your file in that folder or a subfolder in it.

When robot code is started, the working directory is a directory that is not writable. So if you want to write or read from a file, as said before you need to specify the full path. Would definitely recommend somewhere in /home/lvuser

I would bet the problem more likely has to do with runtime.exec(…>>) than with the default path and related suggestions.

For explanations about this I have found the following web-article very useful on this approach and it’s limitations.

  [When Runtime.exec() won't | JavaWorld](www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html)

See specifically “Runtime.exec() is not a command line” in section 2 of 3.