Output(); $e = $p4->Errors(); $w = $p4->Warnings(); $co = count( $o ); $ce = count( $e ); $cw = count( $w ); printf( "There were %d results, %d errors and %d warnings\n\n", $co, $ce, $cw ); for( $idx = 0; $idx < $co; $idx++ ) { printf( "RESULT[ %d ]:\n", $idx ); if( is_array( $o[ $idx ] ) ) { reset( $o[ $idx ] ); while( list( $key, $val ) = each( $o[ $idx ] ) ) { printf( "\t%s\t-> %s\n", $key, $val ); } } else { printf( "\t%s\n", $o[ $idx ] ); } printf( "\n" ); } if( $ce == 0 && $cw == 0 ) return; if( $cw ) { for( $idx = 0; $idx < $cw; ++$idx ) { printf( "WARNING[ %d ]: %s\n", $idx, $w[ $idx ] ); } } if( $ce ) { for( $idx = 0; $idx < $ce; ++$idx ) { printf( "ERROR[ %d ]: %s\n", $idx, $e[ $idx ] ); } } } //------------------------------------------------------------------------------ // Start of main script //------------------------------------------------------------------------------ $p4 = new PerforceClient(); $p4->DebugLevel( 0 ); // Defaults to P4PORT, but here we override. $p4->SetPort( "localhost:1666" ); //------------------------------------------------------------------------------ // Enable tagged mode. Mostly you want this or ParseForms() mode. Without // one or the other, you'll be parsing a lot of output by hand. //------------------------------------------------------------------------------ $p4->Tagged(); //------------------------------------------------------------------------------ // Will convert Perforce forms into hashes and vice-versa. Implies tagged // mode. //------------------------------------------------------------------------------ $p4->ParseForms(); //------------------------------------------------------------------------------ // Connect to server //------------------------------------------------------------------------------ if( ! $p4->Connect() ) { echo( "Failed to connect\n" ); exit( 0 ); } //------------------------------------------------------------------------------ // Run a 'p4 info' and print the results //------------------------------------------------------------------------------ $res = $p4->Run( "info" ); show_results( $p4 ); //------------------------------------------------------------------------------ // Fetch the current definitions of our user account. Note // that Run() returns an ARRAY, so if you're running a // command that only returns one result, you must shift/pop/index // the array //------------------------------------------------------------------------------ $res = $p4->Run( "user", "-o" ); $res = array_shift( $res ); show_results( $p4 ); //------------------------------------------------------------------------------ // Now we can modify the hash we got back and supply it as // input to a Perforce command. This example is commented // out by default so that this script is not invasive. //------------------------------------------------------------------------------ // $res[ "Email" ] = "someone@somewhere.com"; // $p4->SetInput( $res ); // $p4->Run( "user", "-i" ); // show_results( $p4 ); //------------------------------------------------------------------------------ // Similarly, you can do the same thing to submit a change //------------------------------------------------------------------------------ // $change = array_shift( $p4->Run( "change", "-o" ) ); // $change[ "Description" ] = "Some change I wanted to submit"; // $p4->SetInput( $change ); // $p4->Run( "submit", "-i" ); $p4->Disconnect(); ?>