Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How can I run multiple commands with PsExec, and how can I export environment variables?

I can run two commands by doing the below, but when I try to export an environment variable the second command errors out.

Running two commands:

psexec \\servername cmd /c p4 info & dir

^ This works

Trying to export env variable and then run another command:

psexec \\servername cmd /c set P4PORT=xx.xxx.xx.xx & p4 -c client -P ################## -u user diff -f //dir/dir2/dir3/...

^ This errors out on the second command, it complains about the client spec name I'm passing in, but it runs fine if i run just the second command. It's like the first command throws off the second.

Thanks!

share|improve this question

migrated from stackoverflow.com Sep 8 '11 at 4:34

This question came from our site for professional and enthusiast programmers.

add comment

1 Answer

up vote 1 down vote accepted

I believe you will find the second command is running on the local machine, not the remote one. You need to use quote marks like this:

psexec \\servername cmd /c "p4 info & dir"
share|improve this answer
    
perfect, this did it! –  user797963 Sep 7 '11 at 15:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.