Command Runner launched java program fail to list files in network folder

I tried to run the following simple Java program using command line builder runner.

public static void main(String[] args) throws IOException {
File[] xf = (new File("b:

File(filename).listFiles() returns valid File objects if filename is local resource. If filename is remote (e.g. b:\ drive maps to
host\resource, or
host\resource directly) listFile() returns null.

If I run the exact same program from the command line in the agent's command shell, listFile() behaves correctly regardless of if the filename is local or remote resource.. It only does not work if the java program is launched inside the team city's agent runner.

Any idea what the problem may be?

Albert Lee.


I think you should change user account under which agent service is working.

Pavel Sher


Thanks for the quick response. I was suspecting it may be something to do with security.

I changed the TeamCity agent service's log-on account to my user id instead of "SYSTEM". My user id has Administrator authority.

I submited a job again after the change, restart the teamcity services and it still failed the same way:

: c:\was6\as\java\bin\java.exe -cp .
: ** isDir =false
: ** isFile=false
: ** exists=false
: fCommitted=b:\
: **Warning: b:\ is an invalid path.
: Exception in thread "main" java.lang.NullPointerException
: at
: at
: at
: Process exit code: 1
: Build finished

When I run the same program in a command windows in the agent's system, it yeilded the proper output and here is the output:

C:\TeamCity\.BuildServer\config\JPA FVT Run\checkout>java -cp .

    • isDir =true

    • isFile=false

    • exists=true

build level = B:\was_defects/linux/zipper/externals/installables/

p.s. the B: drive is mapped to a network drive

Albert Lee.


I do not think it is actually related to TeamCity agent. I think you should try to debug your code with help of remote debug facility. The issue can also be related to security settings of the java you are using. Try to launch your class with another java.

Pavel Sher


I switched to another JVM (Sun) and it still failed.

There is no JAVA 2 security applied to the jvm. I double checked and there is NO security manager installed.

I started the command runner with a java jvm and enabled remote debug. Launch an agent run instance and attached the jvm to an Eclipse debugger. Stepped into the File.listFiles() method, the class calls out to a native WinNTFileSystem (implements FileSystem interface) to get a String[] of files in this folder. The javadoc indicates the listFiles() returns null if the abstract pathname is NOT a directory. The File.isDirectory() actually returns false. So it looks like it behaves consistently. Somehow the native FileSystem implementation does not recognize remote folder when it is launched fromt within SimpleRunner.

As I noted before, the same sample test program works if it is launched in a command window in the same system where the agent service is run. Both runs uses the same JVM.

I have been scratching my head on who could be the cause of this problem.

Albert Lee.


Have you tried to launch agent via agent.bat?

Pavel Sher


Please sign in to leave a comment.