Open two files side by side from command line

  • Hi everyone,

    I’d like to do what the title says: create one .cmd file that’ll fire up Notepad++ and show me the two files side by side. I have checked the CLI reference and can see how to open two files via command line but I couldn’t see how to do the side-by-side thing.

    The purpose is this: I have created a python script that compares a lot of different text files. Interesting file pairs that need closer investigation are put into separate folders for easy navigation. This works great but I still need to open every file pair and drag them around inside of Notepad++. I’d like to automatically create a .cmd file for each pair that’ll immediately open the files side-by-side and thus reducing the amount of repetitive clicking around.

    Thanks in advance!


    If you’re a Pythoner, doing this using the PythonScript plugin should be fairly easy.
    Do you want to take a look at doing that all by yourself, or do you want some guidance?

    Since you mentioned comparing, you may take a look at the Compare plugin.
    Since I don’t use it, I can’t advise any further on if it can auto-open two files passed in on N++ startup (I doubt it, though).

  • Thank you for the quick reply!

    I did find that plugin but there are 2 issues:

    • I’m not the only one who’ll use this script and I’d prefer solutions that work “out of the box” without extra plugins to install. If it’s not possible without those, okay, better than nothing, but IMO for this case it’s the second choice
    • PythonScript seems to be based on Python 2 which I don’t have installed, never used and honestly didn’t plan to learn/use since it’s deprecated. There is a Python 3 version in development but if I understand the release notes correctly it doesn’t work for non-unicode files (which I have to deal with). I haven’t looked any deeper into this; maybe there’s a workaround for that…

    If you got any other ideas I’d be very thankful! Otherwise I guess I’ll have to try with PythonScript…

    Kind regards,


    just for the record, pythonscript comes with python dll so there is no need to install anything other than the plugin itself.

    Without plugins, the only possible solution I can think of is to create a session file, created by a batch or your python script, and then start npp with the -openSession parameter and the previously created session file.

  • @Ekopalypse I played a bit with the sessions file and the command line options. I don’t fully understand the behavior but I got something that works. Thanks a lot!


  • Oh lord the encodings are killing me…

    Filepaths in the session.xml file somehow need to escape characters even though cp1252 and UTF-8 are well capable of encoding them directly (f.ex. ü)… Then the python xmlcharrefreplace option encodes them with decimal number (ü) instead of hex (&#00FC) - which notepad++ won’t accept. And finally, the CLI option -ope1nSession doesn’t seem to handle filepaths with any of the versions above.

    To make things even better, if anything of all the above doesn’t work, notepad++ doesn’t give you any hint. it just opens a blank new file. I couldn’t find any --verbose option for the CLI either.

    Help would be appreciated before I go insane…


  • @MMMZZZZ said in Open two files side by side from command line:


    not 100% sure what the issue is. The generation of the session file or opening the sessions with npp?

    What I did is the following:

    a) created a file D:\über.txt
    b) created a file D:\temp\ökonmische betrachtung\ärger.txt
    c) moved the second file to the second view
    d) used File->SaveSession and saved it as D:\test_session.xml
    e) open a cmd and started D:\Tests\npp\810\x64\notepad++.exe -openSession D:\test_session.xml

    resulted in


    To reuse this mechanism, I would modify the session.xml file and replace the two filename tags with something unique like %%FILE1%% and %%FILE2%% and then have my script replace them with the real name of the file, making sure they are xml encoded.
    As a template, of course. The script would create the real session file.

Log in to reply